DECLARE @Table TABLE (Col1 INT, Col2 DATETIME)
DECLARE @StartDT DATETIME
DECLARE @tempDT DATETIME
DECLARE @EndDT DATETIME
SET @StartDT = DATEFROMPARTS(YEAR(getdate()),MONTH(getdate()),1)
SET @EndDT = EOMONTH (@StartDT)
set @tempDT=@StartDT
WHILE @StartDT < @EndDT
BEGIN
PRINT
CONVERT(VARCHAR,cast(@tempDT as date))
+ ' - ' +
convert(VARCHAR,cast(DATEADD(dd, 7-(DATEPART(dw, @StartDT)), @StartDT) as date))
SET @StartDT = DATEADD(dd, 7-(DATEPART(dw, @StartDT)), @StartDT)
SET @tempDT = DATEADD(dd,1,@StartDT)
SET @StartDT = DATEADD(WEEK,1,@StartDT)
END
PRINT
CONVERT(VARCHAR,cast(@tempDT as date))
+ ' - ' +
convert(VARCHAR,cast(@EndDT as date))