MySQL ignoring where clause?

I have written a simple sub-query that pulls out the year from a datetime field in a MySQL DB. The WHERE clause checks that the year is >= 2009.  The Query looks like:

SELECT YEAR(EndTime)
FROM `call`
WHERE YEAR(EndTime) >= '2009'

I have tried this in both MySQL Workbench and in SQL Server Management Studio (using a linked server).  The result set contains results that are not valid given the where clause (malformed dates exist in the data set where the year is 5130, etc.).  

Thanks in advance!
selliott80919Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
Try removing the single quotes around 2009 so it's used as a number and not a string.
0
cyberkiwiCommented:
Hi there,

>> malformed dates exist in the data set where the year is 5130
That explains it.
If you have data in your 'call' table with dates in the year 5130, surely that's greater than 2009!!
Data entry error.
To list them, use this

SELECT EndTime
FROM `call`
WHERE YEAR(EndTime) >= 2009
0
cyberkiwiCommented:
Or if you want to ignore the crazy times, use this

SELECT YEAR(EndTime)
FROM `call`
WHERE YEAR(EndTime) between 2009 and 2010
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NerdsOfTechTechnology ScientistCommented:
Simplified
SELECT YEAR(EndTime)
FROM `call`
WHERE YEAR(EndTime) >= 2009

Open in new window

0
NerdsOfTechTechnology ScientistCommented:
make sure that your EndTime column data is correctly formatted too :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.