Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Overlapped Dates
Message
De
20/03/2007 18:00:50
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, États-Unis
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2000
Divers
Thread ID:
01206271
Message ID:
01206298
Vues:
21
>>I have a table with transactional records, and each record has a start and an end date. I am creating a SPROC to insert a record into this table, but I want to make sure that the start date and end date in the record I am inserting does not overlap any of the date ranges in any records in the table.
>>
>>Anybody know how I can accomplish this?
>
>
>IF NOT EXISTS (SELECT * FROM mytable
>		WHERE @StartDate BETWEEN StartDate AND EndDate
>			OR @EndDate BETWEEN StartDate AND EndDate)
>	INSERT INTO ...
>
Sergey,
I thought about doing something like that, but I think I would miss the case where @StartDate is before any other StartDates AND @EndDate is after any other EndDates... for example, a bogus record with a @StartDate of 1/1/1900 and an @EndDate of 1/1/2500 would be added, because all of the other records have start dates and end dates only a few days apart.

Or am I wrong?
Very fitting: http://xkcd.com/386/
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform