如何在SQL Server中的时间戳和时间戳之间

时间:2017-08-14 02:36:47

标签: sql 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之间查询

请帮忙

由于

1 个答案:

答案 0 :(得分: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