I have a event table that has the following columns:
StartDate datetime
EndDate datetime
StartTime nvarchar(10)
EndTime nvarchar(10)
Let’s say a record has these values in the table:
StartDate: 2011-12-22 00:00:00.000
EndDate: 2011-12-22 00:00:00.000
StartTime: 4:00 PM
EndTime: 5:00 PM
Now, if someone comes to schedule an event, I need to make sure he can’t schedule it for the same time or between the start and end times of this existing event.
So, he can schedule from 5:00 PM to 6:00 PM or from 11:00 AM to 4:00 PM but not 11:00 AM to 5:00 PM or 4:30 PM to 5:00 PM.
How can I check for this? I know this isn’t the best design for this table, but I have to stick to this design, else we will have to change a lot of middle layer and client side code.
Try this
If count(*) > 0, an appointment exists. If not, the spot is free