Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
kattlees
Starting Member
3 Posts |
Posted - 2013-10-31 : 12:51:34
|
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 2009We would like this to automatically update each year without having to go in and change the code. |
|
bitsmed
Aged Yak Warrior
545 Posts |
Posted - 2013-10-31 : 13:04:10
|
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 */ |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2013-11-01 : 07:44:38
|
WHERE datehired>=dateadd(year,datediff(year,0,getdate())-4,0) anddatehired<dateadd(year,datediff(year,0,getdate())-3,0)MadhivananFailing to plan is Planning to fail |
|
|
|
|
|