Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 302
  • Last Modified:

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?
0
Grogel
Asked:
Grogel
  • 2
1 Solution
 
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
 
tim_csCommented:
If Date is a datetime field then why not just...

WHERE DATEPART(YY, Date) = 2012
0
 
GrogelAuthor Commented:
That's it, thank you.
0

Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now