Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How To - Create Table Variable of dates MWF 2 years
Message
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
How To - Create Table Variable of dates MWF 2 years
Environment versions
SQL Server:
SQL Server 2000
Miscellaneous
Thread ID:
01439385
Message ID:
01439385
Views:
95
Hey Everyone

I was wondering if anyone had a quick set of SQL code to create a table variable and populate with two years of dates based off MWD or Tue/Thur/Sat

I will have start date and the string of valid dow. I only need to populate the Workdate and DOW in the table. Other fields will be blank until later processing. I'm not a SQL date wizard (or any wizard) so I didn't know if there is an easy way to figure all the dates for an insert into @TableOfDates.

Thanks for any help.
declare @StartDate varchar(10) = '12/16/2009'
declare @DowsOfWeek = '2,4,6'    -- MWF Example
declare @TableOfDates table
(
WorkDate varchar(10),
WorkDateNumber int,
SchedStart varchar(10),
SchedEnd   varchar(10),
VarianceFromPlanned int,
Booked bit
)
-- 2,4,6 is MWF
-- 3,5,7 is TTS
-------------------------------------------------------------------------------------------------------------------------------------------------------------
WorkDate    WorkDateNumber       SchedStart                SchedEnd          VarianceFromPlanned  Booked
--------------------------------------------------------------------------------------------------------------------------------------------------------------
12/16/2009        4  
121/8/2009        6
12/21/2009        2                           
12/23/2009        4
Next
Reply
Map
View

Click here to load this message in the networking platform