Search query only by year.

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?
GrogelAsked:
Who is Participating?
 
tim_csConnect With a Mentor Commented:
If Date is a datetime field then why not just...

WHERE DATEPART(YY, Date) = 2012
0
 
Steve WalesSenior Database AdministratorCommented:
How about this:

If the column ends in yyyy:

Select max(num) from SomeTable where Date like '%2012'
0
 
GrogelAuthor 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.
0
 
GrogelAuthor Commented:
That's it, thank you.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.