Question

What I have here is very strange to me...

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'

Simple right?

Now please look at returned data:

enter image description here

Ekhmmm... why... Why... WHYYYY? :) As you see proper dates are there, but comparison kills results.

I have SQL Server 2005 Express and the Management Studio Express

Was it helpful?

Solution

'2013-03-08 00:00:00.000' is not an unambiguous format when casting to datetime. It can either mean 3rd of August or 8th of March.

It depends upon your DATEFORMAT settings (which in turn depends upon the language of your login).

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

Returns

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

Use

WHERE BARCODE='25405187' AND DATA = '20130308 00:00:00.000' 

Or more simply

WHERE BARCODE='25405187' AND DATA = '20130308' 

OTHER TIPS

Try this standard (ISO) date representation:

Select BARCODE, DATA 
from HISTORIA 
WHERE BARCODE='25405187' AND DATA = '2013-03-08T00:00:00.000'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top