Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

lab reservation query

$
0
0

I've following table

LabType         StartDate                                              EndDate

2                    2013-09-03 09:30:00.000                     2013-09-03 10:30:00.000

2                    2013-09-03 11:30:00.000                     2013-09-03 12:30:00.000

7                    2013-09-03 13:30:00.000                     2013-09-03 15:30:00.000

i have  a procedure with parameters (@LabType,@StartDate,@EndDate)

I'm trying to write query that check @Startdatetimetime ,@EndDatetimetime , @LabType if already reserved
display 'Already Reserved' if not 'Avaiable' , tried query below and other ways but still allow overlap on time, any suggestions?

Thanks

 @Startdatetime <= LabReservation.FromDateTime AND  @EndDatetime  >= LabReservation.ToDateTime   
       
 AND
 @LabType NOT IN (                               
  SELECT LabReservation.LabType FROM LabReservation
  WHERE  @Startdatetime >= LabReservation.ToDateTime AND  @EndDatetime   <= LabReservation.FromDateTime

)


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>