2017-08-14 127 views
-2

我有兩個疑問如何在SQL Server時間戳和時間戳之間

查詢#1作品:

SELECT * 
FROM dbPLC.dbo.PLC_CPacking3KW2P3 AS A 
INNER JOIN dbPLC.dbo.PLC_CPacking3KW2P3 AS B ON B.NoUrut = A.NoUrut - 1 
WHERE A.Nilai - B.Nilai = 1 
    AND CONVERT(DATE, A.TimeStamp) = CONVERT(DATE, '2017/08/13') 
    AND DATEPART(HOUR, DATEADD(DAY, 1, A.TimeStamp)) BETWEEN 7 AND 15 

但我想07:00:00和15:00:00

之間查詢

請幫

感謝

回答

0

你可以這樣做

convert(varchar(8),convert(time,A.TimeStamp)) between '07:00:00' and '15:00:00' 

,而不是這個

DATEPART(HOUR,DATEADD(DAY,1,A.TimeStamp)) between 7 and 15