Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 how to generate a date sequence

Author  Topic 

jeff06
Posting Yak Master

166 Posts

Posted - 2008-01-08 : 16:38:26
I want to create a table which contain on col date
which contail all weekday date from 8/7/2006 to 12/14/2007

the table should look like:
date
8/7/2006
8/8/2006
8/9/2006
8/10/2006
8/11/2006
8/14/2006
----
12/14/2006
Thanks

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2008-01-08 : 16:45:09
here is a select statement to get the dates you want. I'll leave the actual table creation and insert statement up to you (or sometone else).
SELECT DISTINCT DATEADD(DAY, number, '8/7/2006') AS Date
FROM Master.dbo.spt_values
WHERE number between 0 and 494
ORDER BY DATEADD(DAY, number, '8/7/2006')
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2008-01-08 : 17:35:29
You can use the function on this link to generate a date table.

Date Table Function F_TABLE_DATE
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=61519




CODO ERGO SUM
Go to Top of Page
   

- Advertisement -