Hi Naveen
You can use the below function to get previous month...
DECLARE @Input AS DATETIME
SET @Input = NULL;
WITH CurrentDate AS
(
SELECT ThisMonthFirstDay = DATEADD( MM, DATEDIFF(MM,0,ISNULL(@Input,GETDATE())) ,0)
)
, Numbers(N) AS
(
SELECT -1 --PREVIOUS MONTH
--SELECT 0 --CURRENT MONTH
--UNION ALL SELECT -1
--UNION ALL SELECT -2
)
SELECT SlNo = CrsApp.N + 3
,[Month] = DATENAME(M, CrsApp.StartDates) + ' ' + CAST(YEAR(CrsApp.StartDates) AS VARCHAR(4))
,StartDate = CONVERT(VARCHAR(10), CrsApp.StartDates, 120)
,EndDate = CONVERT(VARCHAR(10), DATEADD(DD,-1, DATEADD(MM,1,CrsApp.StartDates)), 120)
FROM CurrentDate CD
CROSS APPLY (
SELECT N , DATEADD(MM,N.N,CD.ThisMonthFirstDay)
FROM Numbers N
) CrsApp(N, StartDates)
<pre lang="SQL">
Regards
Willington