Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How To - Create Table Variable of dates MWF 2 years
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2000
Divers
Thread ID:
01439385
Message ID:
01439390
Vues:
43
See this link http://sqlserver2000.databases.aspfaq.com/why-should-i-consider-using-an-auxiliary-calendar-table.html - it should solve your problem.
insert into @TableOfDates (WorkDate, WorkDateNumber) 
 SELECT DATEADD(DAY, Number, @StartDate) , DATEPART(week,DATEADD(DAY, Number, @StartDate)) 
        FROM FROM master..spt_values WHERE type = 'P' AND number <= @Days and  
       DATEPART(week,DATEADD(DAY, Number, @StartDate))  IN (2,4,6)
        ORDER BY Number
>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
>
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform