Search query only by year.

Member_2_4286571
Member_2_4286571 used Ask the Experts™
on
Hi guys,

I need to select highest number based on specific year.

Select max(num) from SomeTable where Date like '%2012%'

now this is not good since month 12 and day 20 in 2013 year will also respond to this query.

my date format is ddMMyyyy.

Any suggestions?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Steve WalesSenior Database Administrator

Commented:
How about this:

If the column ends in yyyy:

Select max(num) from SomeTable where Date like '%2012'

Author

Commented:
Unfortunately in database date looks like this 2012-10-29 00:00:00.000.

I am using ddMMyyyy in VB.net, but in database is displayed differently.
Commented:
If Date is a datetime field then why not just...

WHERE DATEPART(YY, Date) = 2012

Author

Commented:
That's it, thank you.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial