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)
 sql recurring day

Author  Topic 

akpaga
Constraint Violating Yak Guru

331 Posts

Posted - 2008-02-12 : 14:55:42
hi
i have table x which has fields (recurring(yes or no),startdate,endate,dayoftheweek)
i want to know if i select startdate as 02/03/2008 and enddate as 04/05/2008 and dayoftheweek as thursday
i want the table to be populated for every thursday that is available betwwen the two dates i.e if there are 12 thursdays i want the table to be populated 12 times . i am using sql server 2000.
thanks

akpaga

jhocutt
Constraint Violating Yak Guru

385 Posts

Posted - 2008-02-12 : 15:05:46
You want the table populated???
Or you want a result set that has the 12 records in it??


"God does not play dice" -- Albert Einstein
"Not only does God play dice, but he sometimes throws them where they cannot be seen."
-- Stephen Hawking
Go to Top of Page

akpaga
Constraint Violating Yak Guru

331 Posts

Posted - 2008-02-12 : 15:16:19
hi
i want the table populated with an insert statement
thanks
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2008-02-12 : 15:31:26
[code]declare @start_date datetime
declare @end_date datetime
select @start_date = '20080203'
select @end_date = '20080405'

select
[DATE],
from
--Date Table Function F_TABLE_DATE available here:
--http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=61519
dbo.F_TABLE_DATE ( @start_date,@end_date)
where
[DAY_OF_WEEK] = 5

Results:
DATE
------------------------------------------------------
2008-02-07 00:00:00.000
2008-02-14 00:00:00.000
2008-02-21 00:00:00.000
2008-02-28 00:00:00.000
2008-03-06 00:00:00.000
2008-03-13 00:00:00.000
2008-03-20 00:00:00.000
2008-03-27 00:00:00.000
2008-04-03 00:00:00.000

(9 row(s) affected)
[/code]

CODO ERGO SUM
Go to Top of Page
   

- Advertisement -