Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Overlapping time in booking system.

Author  Topic 

Deltaur
Starting Member

29 Posts

Posted - 2009-12-09 : 06:59:33
Hi,

I have little problem to solve.

Let's say that i have two datetime ranges in my database

row 1 start 2009-12-9 07:00:00 end 2009-12-9 11:00:00
row 2 start 2009-12-9 13:00:00 end 2009-12-9 15:00:00

i am trying to check do i have slot in certain time. i am trying to insert time start 2009-12-9 11:00:00 end 13:00:00 to fill a slot it should insert because there is slot, or is there? (should i use end time like 10:59:59) . how i check is there overlapping time?

like if i am trying to insert start 2009-12-9 14:00 end 2009-12-9 16:00 it should return that it is not possible to insert data to that time range because of overlapping time.

RyanRandall
Master Smack Fu Yak Hacker

1074 Posts

Posted - 2009-12-09 : 07:30:54
[code]if exists (select * from YourTable where start < @NewSlotEnd and @NewSlotStart < [end])
print 'Slot not available'
else
print 'Slot available'[/code]

Ryan Randall - Yak of all trades
Solutions are easy. Understanding the problem, now, that's the hard part.
Go to Top of Page

Deltaur
Starting Member

29 Posts

Posted - 2009-12-09 : 07:58:36
Awesome!

This answer was so front of my nose but i had variables wrong.

Thank you!
Go to Top of Page

RyanRandall
Master Smack Fu Yak Hacker

1074 Posts

Posted - 2009-12-09 : 08:01:54
I remember being surprised at how simple this was when I first worked it out (many years ago). It feels as though it should be more complicated!


Ryan Randall - Yak of all trades
Solutions are easy. Understanding the problem, now, that's the hard part.
Go to Top of Page
   

- Advertisement -