Declare @StartDate Datetime, @EndDate Datetime
Set @StartDate = '01/01/2009' Set @EndDate = '01/30/2009';
WITH WeekDay(FirstDay,NextDay) AS
(SELECT @StartDate AS StartDate, DATEADD(d,1,@StartDate) AS NextDay
UNION ALL
SELECT NextDay AS FirstDay, DATEADD(D,1,NextDay) AS NextDay FROM WeekDay
WHERE NextDay BETWEEN @StartDate AND @EndDate)
(SELECT @StartDate AS StartDate, DATEADD(d,1,@StartDate) AS NextDay
UNION ALL
SELECT NextDay AS FirstDay, DATEADD(D,1,NextDay) AS NextDay FROM WeekDay
WHERE NextDay BETWEEN @StartDate AND @EndDate)
SELECT FirstDay 'Sundays' FROM WeekDay WHERE DATENAME(DW,FirstDay) = 'Sunday'
No comments:
Post a Comment