Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
SQL
select count(*) from passengermaster where (ticket_issue_date is not null and ticket_issue_date > 2009-01-01);

Not every registered passenger will have been issued a ticket, but for those that have, I want a count of
all tickets issued after 01/01/09.
I am getting the correct answer, but for good measure I also get Error 1292 - Incorrect value.
Any assistance in eliminating the error is much appreciated
Posted

1 solution

You shouldn't need the ... is not null bit because null is not greater than any date.

The error is because the date is not quoted, so it is comparing the date in the column with the number 2007 (2009 - 1 - 1).

Try this instead:
select count(*) from passengermaster where ticket_issue_date > '2009-01-01';
 
Share this answer
 
Comments
Ger Hayden 28-Jun-11 16:11pm    
Perfect Graham. I am going to have to review other queries and either include quotes or go YYYYMMDD because I have unreliable results using YYYY-MM-DD without quotes. The problem with unreliable as opposed to consistant is that they can give the illusion of correct in a lightweight test.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900