all groups > sql server mseq > february 2006 >
You're in the

sql server mseq

group:

question on date (or string after using convert function) comparis


question on date (or string after using convert function) comparis kei
2/13/2006 7:05:26 PM
sql server mseq:
select case when '02/12/2005' >= '01/02/2006' then 'T' else 'F' end

Re: question on date (or string after using convert function) comparis Hugo Kornelis
2/14/2006 10:56:40 PM
[quoted text, click to view]

Hi kei,

You are comparing two string constants. They may look like dates to you
and me (though probably not the same dates - I'm from the part of the
world that uses dd/mm/yyyy), but SQL Server doesn't try to interpret
what you write - it takes you literally.

You could try
SELECT CASE WHEN CAST('02/12/2005' AS datetime) >=
CAST('01/02/2006' AS datetime) THEN 'T' ELSE 'F' END
and pray that SQL Server interprets the ambiguous date format the same
way you do.

Or you could switch to a non-ambiguous date format:
SELECT CASE WHEN CAST('20051202' AS datetime) >=
CAST('20060201' AS datetime) THEN 'T' ELSE 'F' END

For more information, check Tibor Karaszi's article on SQL Server date
and time handling: http://www.karaszi.com/SQLServer/info_datetime.asp

--
AddThis Social Bookmark Button