?
Solved

Search query only by year.

Posted on 2012-12-21
4
Medium Priority
?
286 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 23

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 2000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

719 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