我在这里对我来说很奇怪......
Select BARCODE, DATA
from HISTORIA
WHERE BARCODE='25405187' AND DATA = '2013-03-08 00:00:00.000'
Select BARCODE, DATA
from HISTORIA
WHERE BARCODE='25405187'
简单吧?
现在请查看返回的数据:
Ekhmmm ......为什么......为什么......为什么? :)当你看到正确的日期,但比较会导致结果。
我有SQL Server 2005 Express和Management Studio Express
答案 0 :(得分:3)
'2013-03-08 00:00:00.000'
时, datetime
为not an unambiguous format。它可以是8月3日或3月8日。
这取决于您的DATEFORMAT
设置(这取决于您登录的语言)。
SET LANGUAGE english
SELECT CAST('2013-03-08 00:00:00.000' AS DATETIME) AS english
SET LANGUAGE british
SELECT CAST('2013-03-08 00:00:00.000' AS DATETIME) AS british
返回
Changed language setting to us_english.
english
-----------------------
2013-03-08 00:00:00.000
Changed language setting to British.
british
-----------------------
2013-08-03 00:00:00.000
使用
WHERE BARCODE='25405187' AND DATA = '20130308 00:00:00.000'
或更简单
WHERE BARCODE='25405187' AND DATA = '20130308'
答案 1 :(得分:1)
尝试此标准(ISO)日期表示:
Select BARCODE, DATA
from HISTORIA
WHERE BARCODE='25405187' AND DATA = '2013-03-08T00:00:00.000'