Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Selecting dates not in a date set
Message
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
01241975
Message ID:
01242143
Views:
15
>Hi, it's very easy to create a range of dates using CTEs...
>
>Here's an example....suppose I want to create a CTE of Saturday dates from 1-6-07 to 7-7-07...
>
>
>DECLARE @StartDate DATETIME, @EndDate DATETIME
>SET @StartDate = '1-6-2007'   -- you might want to verify this is a saturday date
>SET @EndDate = '7-7-2007'
>
>;WITH DateCTE(WeekEndingCTE)  AS
>        -- anchor query
>        (SELECT @StartDate AS WeekEnding
>                   UNION ALL
>                       -- recursive query
>                       SELECT WeekEnding + 7 AS WeekEnding FROM WeekEndingCTE WHERE WeekEnding < @EndDate )
>
>-- Now do something wtih WeekEndingCTE
>
>
>That will give you a list of every Saturday date in that date range.
>
>(now, in JB's example, you'd add 1 day instead of 7, if you need every date in the range)
>
>Let me know if that helps...
>Kevin


I hope this could help to John, but this really helps to me.
Thank you.
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform