SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 SQL ISSUE...
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

gvmk27
Starting Member

31 Posts

Posted - 05/21/2012 :  12:40:01  Show Profile  Reply with Quote
Hi

I was trying to develop appointment calendar, admin needs to define meeting frequencies
If a meeting is already booked from 9.00 to 13:00 and 14:00 to 15:00,
he can book a slot for 13:00 to 14:00. I was trying to check for the existing records using between, but below SQL show meeting already exists for that duration


declare @starttime time(0)
declare @endtime time(0)
set @starttime = '13:00:00'
set @endtime = '14:00:00'

SELECT CDSD.StartTime, CDSD.EndTime, CDSD.TimeSlotDuration
FROM CenterDowSetting CDS
INNER JOIN CenterDowSettingDetail CDSD
ON CDS.CenterDowSettingID = CDSD.CenterDowSettingID
WHERE CDS.DowID = @DowID -- DayId
AND (((StartTime < convert(time(0), @starttime)) AND (EndTime <= convert(time(0), @starttime)))
OR (EndTime >= convert(time(0), @endtime)))

Thanks for your help / advice in advance.

visakh16
Very Important crosS Applying yaK Herder

India
47040 Posts

Posted - 05/21/2012 :  16:40:21  Show Profile  Reply with Quote
whats the datatype of STartTime and EndTime in CenterDowSettingDetail table?

Also current is looking only for slots that comes outside the range chosen.

i think the check should have been

IF NOT EXISTS(SELECT 1 FROM CenterDowSetting CDS
INNER JOIN CenterDowSettingDetail CDSD
ON CDS.CenterDowSettingID = CDSD.CenterDowSettingID
WHERE CDS.DowID = @DowID 
AND ((StartTime < @starttime AND EndTime >  @starttime)
OR (StartTime < @endtime AND EndTime >  @endtime ))
)
 SELECT 'No Conflicts'
ELSE 
 SELECT 'Conflicts'


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

gvmk27
Starting Member

31 Posts

Posted - 05/22/2012 :  11:06:12  Show Profile  Reply with Quote
Thanks for your time Visakh..

Startime & endtime data type is Time(0)

But this gets failed in the below scenario

Meetings are already there for below interval

09:00:00 to 13:00:00
14:00:00 to 15:30:00
16:30:00 to 17:30:00

If I try to define for outer boundaries, I mean

08:00:00 to 18:00:00

Thanks
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000