Solved

Search query only by year.

Posted on 2012-12-21
4
274 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After restoring a Microsoft SQL Server database (.bak) from backup or attaching .mdf file, you may run into "Error '15023' User or role already exists in the current database" when you use the "User Mapping" SQL Management Studio functionality to al…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

626 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