2012-04-24 11 views
1

私は与えられた時間は、2つの時間間隔の間にあるチェックする必要がT-SQL時間論理

storeID starttime endtime 
    A  1:00AM 4:00PM 
    B  7:30PM 6:00AM 
    C  2:00AM 4:00AM 

ような3列のデータを有しています。

そのロジックのT-SQLステートメントを提案できますか?

私が午前1:00に開いている店舗を取得したいと思えば、結果としてA, Bを得なければなりません。

答えて

1
declare @testTime time 
select @testTime = '01:00' 
select storeId from openinghours 
    where (startTime<=endTime and @testTime >=startTime and @testTime <=endTime) 
     OR (startTime>endTime and (@testTime <startTime OR @testTime > endTime)) 
0
declare @testTime time 
select @testTime = '01:00' 
select storeId from openinghours where @testime between starttime and endtime