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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Date Query
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

28 Posts

Posted - 12/12/2010 :  06:45:58  Show Profile  Reply with Quote
Hi guys

I'm wondering if this is possible.

In my events table I have the following columns: Start Date, End Date and 7 columns for the days of the week which are set as INT with the value of 0 or 1 if true.

If there is a single entry in the table with a start date of the 18th Nov 2010 and end date of 30th Dec 2010 and the Thursday field is flagged as 1 would it be possible to return a resultset which would display each Thursday between and including the two dates?

Thanks in advance!

Patron Saint of Lost Yaks

30421 Posts

Posted - 12/12/2010 :  07:00:41  Show Profile  Visit SwePeso's Homepage  Reply with Quote

SELECT		DATEADD(DAY, v.number, x.StartDate) AS Thursday
			SELECT		StartDate,
			FROM		dbo.Table1
			GROUP BY	StartDate,
			HAVING		SUM(CASE WHEN Thursday = 1 THEN 1 ELSE 0 END) = 1
		) AS x
INNER JOIN	master..spt_values AS v ON v.type = 'P'
			AND v.number BETWEEN 0 AND DATEDIFF(DAY, x.StartDate, x.EndDate)
WHERE		DATEDIFF(DAY, 0, DATEADD(DAY, v.number, x.StartDate)) % 7 = 3

N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

Flowing Fount of Yak Knowledge

1464 Posts

Posted - 12/12/2010 :  07:06:46  Show Profile  Send dataguru1971 an AOL message  Send dataguru1971 a Yahoo! Message  Reply with Quote
SELECT StartDate,Enddate
FROM [Table]
Where (datepart(WEEKDAY,startdate) = 5 or (datepart(WEEKDAY,enddate)) = 5
And StartDate >= '2010118' and EndDate <='20101230'

The above will return each startdate and enddate where the date is a thursday and between the dates you indicated

You don't really need the 7 columns. The date functions allow you to identify the weekday pretty simply.

Poor planning on your part does not constitute an emergency on my part.

Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000