1

私は次のSQLを持っています、

SELECT dims_branchcode, 
       dims_documentname, 
       dims_branchname, 
       Count(dims_documentname) AS NoofRequestWithinCutoff, 
       track.sentdate 
FROM   track 
       INNER JOIN td_wf_dims394 
               ON track.documentno = td_wf_dims394.sno 
WHERE  ( track.indexcardname = 'TD_WF_DIMS394' 
         AND track.sender = 0 
         AND Datepart(hh, senttime) <= 16 ) 
GROUP  BY dims_branchcode, 
          dims_branchname, 
          dims_documentname, 
          sentdate 
ORDER  BY track.sentdate 

これは16時間うまく機能しています。しかし、時間と分を指定するには16時間30分必要です

4

1 に答える 1

4

990 が (16*60) + 30 分である条件を追加します。

AND DATEDIFF(mi, DATEADD(dd, 0, DATEDIFF(dd, 0, senttime)), senttime)<=990

それ以外の

AND Datepart(hh, senttime) <= 16

サンプル データで確認します。

declare @tbl as table(dts datetime)

insert into @tbl values 
('2012-01-07 17:27'), 
('2012-01-07 16:27'), 
('2012-02-22 11:36')

select * From @tbl

--condition datepart(hh, dts)<=16 and datepart(minute, dts)<=30, which doesnot include the 3rd row
select * From @tbl where datepart(hh, dts)<=16 and datepart(minute, dts)<=30 

--gives the desired result
select * From @tbl where DATEDIFF(mi, DATEADD(dd, 0, DATEDIFF(dd, 0, dts)), dts)<=990
于 2013-05-02T10:10:29.280 に答える