2017-04-21 108 views
-1

創建查詢如何DATEADD(DAY,1,TIMESTAMP)在SQL WHERE

SELECT TOP 1 A.TimeStamp FROM dbplc.dbo.PLC_CInputKiln1P1 A 
WHERE CONVERT(DATE,DATEADD(DAY,1,TimeStamp)) = '2017-04-11' 
AND DATEPART(HOUR,DATEADD(DAY,1,TimeStamp))=7 
ORDER BY TimeStamp 

結果上面的查詢,這是

2017年4月10日07:00:04.450

我想要他這樣的結果

2017-04-11 07:00:00 04.450天+ 1

+1

'DATEPART(HOUR,DATEADD(DAY,1,時間戳))= 7'如何增加一天你而改變你的'datetime'的小時部分領域? – Jens

+0

在你想要的結果中,「DAY + 1」是什麼?或者你只想'選擇TOP 1 DateAdd(日,1,A.TimeStamp)....' – TriV

回答

0

試試這個:

SELECT TOP 1 A.TimeStamp FROM dbplc.dbo.PLC_CInputKiln1P1 A 
WHERE CONVERT(DATE,TimeStamp) = '2017-04-11' 
AND DATEPART(HOUR,TimeStamp)=7 
ORDER BY TimeStamp;