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 2000 Forums
 Transact-SQL (2000)
 SQL query

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-08-02 : 10:50:18
Gangs writes "I have a table that stores beginning Date, ending Date in two different columns and other information. This is an event's start date, end date, in a scheduler program.
(Begin date:'2006-12-06 9:00:00.000', End Date: '2006-12-06 10:00:00.000')

So if someone else wants to schedule an event (The new event will also have the start date, end date in the above format) within that time range it shouldn't be allowed. How can I write a query to see whether any events exist within the new event's time range.


I tried something along this line but doesn’t produce the right result all the time:

SELECT * FROM Events_tbl WHERE
BeginningDate BETWEEN '2006-12-06 9:00:00.000' AND '2006-12-06 10:00:00.000' OR
EndingDate BETWEEN '2006-12-06 9:00:00.000' AND '2006-12-06 10:00:00.000'



Thank you very much in advance for your answer."

Kristen
Test

22859 Posts

Posted - 2005-08-02 : 10:56:32
Welcome to SQLTeam Gangs!

Presumably a BEGIN at the exact time of an existing END is allowed?

Dunno if this does the job:

SELECT *
FROM Events_tbl
WHERE (BeginningDate >= '2006-12-06 9:00:00.000'
AND BeginningDate < '2006-12-06 10:00:00.000')
OR (EndingDate > '2006-12-06 9:00:00.000'
AND EndingDate <= '2006-12-06 10:00:00.000')

Kristen
Go to Top of Page
   

- Advertisement -