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: CollateralBooki ng
-- 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 CollateralBooki ng
WHERE (((@CBdDateTime From > CBdDateTimeFrom ) AND (@CBdDateTimeFr om < CBdDateTimeTo))
OR ((@CBdDateTimeT o > CBdDateTimeFrom ) AND (@CBdDateTimeTo < CBdDateTimeTo)) )
AND (CBcPartNumber = @CBcPartNumber) ) <> 0
BEGIN
-- Return an error.
END
-- ... Other checks & finally, the insert/update.
--
Posted via
http://dbforums.com