在我的工作上,我嘗試創建一個查詢以從SQL數據庫中獲取一些信息。這是行之有效的,但是當我嘗試使用日期範圍時,它會停止工作。如何從日期間的SQL數據庫中選擇東西?
我已想出了DATEPART函數,
SELECT
*
FROM
InlogLog as il
INNER JOIN
ComputerIdentity as ci
ON il.Computer = ci.Description
WHERE ci.Location
LIKE 'E18%'
AND ci.MakeModelID = 9
AND DATEPART(YY,il.Datum) = 2016
AND DATEPART(MM,il.Datum) = 10
AND DATEPART(DD,il.Datum) = 03
ORDER BY il.Computer
在上面的例子中,我不能指定兩個日期之間的範圍。 我還試圖使用本示例
SELECT
*
FROM
InlogLog as il
INNER JOIN
ComputerIdentity as ci
ON il.Computer = ci.Description
WHERE ci.Location
LIKE 'E18%'
AND ci.MakeModelID = 9
AND il.Datum = '2016-06-17 09:57:00.000'
但是這導致一個錯誤消息
varchar數據類型爲datetime數據類型的轉換導致外的範圍內的值。
如何讓下一個示例工作?
SELECT
*
FROM
InlogLog as il
INNER JOIN
ComputerIdentity as ci
ON il.Computer = ci.Description
WHERE ci.Location
LIKE 'E18%'
AND ci.MakeModelID = 9
AND il.Datum '2016-06-17 09:57:00.000' BETWEEN '2016-06-18 00:00:00.000'
這是解決方案,非常感謝! –