Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Anniversary Date
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

3 Posts

Posted - 10/31/2013 :  12:51:34  Show Profile  Reply with Quote
I am struggling with this. We want to pull everyone that is going to have a 5 year anniversary in 2014. We have a field of DateHired which is yyyy-mm-dd format. How do I pull everyone who was hired in 2009

We would like this to automatically update each year without having to go in and change the code.

Aged Yak Warrior

545 Posts

Posted - 10/31/2013 :  13:04:10  Show Profile  Reply with Quote
Maybe this:

select *
  from yourtable
 where datehired like cast(year(getdate())-5 as char(4))+'%'   /* this line if datehired is char type */
 where year(datehired)=year(getdate())-5                       /* this line if datehired is date/datetime type */
Go to Top of Page

Premature Yak Congratulator

22864 Posts

Posted - 11/01/2013 :  07:44:38  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
datehired>=dateadd(year,datediff(year,0,getdate())-4,0) and


Failing to plan is Planning to fail
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000