View Single Post

   
  #1 (permalink)  
Old 02-28-2008, 06:39 PM
axion_sa
 
Posts: n/a
Default Date/Time overlaps - urgent.


Hi,



What I have is a booking table, and when updating/inserting I need to
ensure that there are no date/time overlaps. The problem I'm having is
that while the following script works for events on the same day, it
fails miserably when a booking starts on a previous day.



I've just spent the last hour going through previous posts and just
can't seem to it right.



My DB structure (Sql Server 2000):

Table: CollateralBooking

-- CBID - int, identity(1, 1)

-- CBcPartNumber - varchar(50) (foreign key)

-- CBdDateTimeFrom - smalldatetime

-- CBdDateTimeTo - smalldatetime

-- CBcAlias - varchar(50) (foreign key)



My current script (in a stored proc):


IF (SELECT COUNT(*) FROM CollateralBooking
WHERE (((@CBdDateTimeFrom > CBdDateTimeFrom) AND (@CBdDateTimeFrom < CBdDateTimeTo))
OR ((@CBdDateTimeTo > CBdDateTimeFrom) AND (@CBdDateTimeTo < CBdDateTimeTo)))
AND (CBcPartNumber = @CBcPartNumber)) <> 0
BEGIN
-- Return an error.
END

-- ... Other checks & finally, the insert/update.


--
Posted via http://dbforums.com
Reply With Quote