views:

895

answers:

3

Hi,

I am having an Event Management System in which i want,

If an event is registered for 5 days (21 jan 2009 to 26 Jan 2009) Then if another person wants to register an event between 22 jan 2009 to 24 jan 2009 then it will not allow to register. I want to check this using SQL query, so please tell me how can i do this.

+4  A: 

SELECT *
FROM events e
WHERE (@startDate BETWEEN e.startDate and e.endDate)
OR (@endDate BETWEEN e.startDate and e.endDate)
OR (@startDate < e.startDate AND @endDate > e.endDate)

le dorfier
Somehow I don't think he's already into stored procedures...
Tomalak
+1  A: 

Lookup DATEDIFF in SQL help.

Charles Graham
+4  A: 

Just a to complete other answers, you have a good article on How to Search for Date and Time Values Using SQL Server 2000

It reminds you about how date/time values are stored (two date/time data types: datetime and smalldatetime)

It also points out Datetime and smalldatetime are like the floating-point data types, float and real, in that they’re approximate numerics. That means the value retrieved from SQL Server may be different from the value that was originally stored.

Plus, it warns about Database designers who don’t always use date/time columns appropriately. At the time the database is designed, each date/time column should be identified as to whether it will store both dates and times, dates only, or times only.

It closes with practical queries on data/time.

You also have a good description of DATEADD and DATEDIFF here.

VonC