Solved

Search query only by year.

Posted on 2012-12-21
4
266 Views
Last Modified: 2012-12-21
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
Comment
Question by:Grogel
  • 2
4 Comments
 
LVL 22

Expert Comment

by:Steve Wales
ID: 38713625
How about this:

If the column ends in yyyy:

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

Author Comment

by:Grogel
ID: 38713700
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
 
LVL 15

Accepted Solution

by:
tim_cs earned 500 total points
ID: 38713739
If Date is a datetime field then why not just...

WHERE DATEPART(YY, Date) = 2012
0
 

Author Comment

by:Grogel
ID: 38713746
That's it, thank you.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now