March 2, 2010 at 6:38 am
I have a datetime field 'create_date', which is failing for a greater than comparison.
The query is
select create_date,fname
from tblTest
where CONVERT(char(10),create_date,101) >= '03/02/2009'
what would be the correct syntax for comparison?
March 2, 2010 at 6:49 am
Why you are converting a datetime column to char and then doing a comparison?
When you say it is failing, does you get any errors? If not, what data you are expecting the query to be returned?
--Ramesh
March 2, 2010 at 6:56 am
I want all records with create_date >='03/02/2009'
The query is ignoring the where clause & returning me all rows from the table
create_date is a datetime field.
Thanks
March 2, 2010 at 7:06 am
You cannot use text as a comparison. Keep the datatime data type. You are converting that to text, SQL cannot use text in a greater than or less than.
Also, remove the single quotes from around the date. That should get you the resultset that you need
Andrew SQLDBA
March 2, 2010 at 7:17 am
Thanks, followed the point.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply