1

次のような3列のデータがあります

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

指定された時間が2つの時間間隔の間にあることを確認する必要があります。

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

午前 1 時に開いている店舗を取得したい場合A, B、結果として取得する必要があります。

4

2 に答える 2

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))
于 2012-04-24T01:14:59.440 に答える
0
declare @testTime time 
select @testTime = '01:00' 
select storeId from openinghours where @testime between starttime and endtime
于 2012-04-24T08:38:41.327 に答える