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 |
|
craigwg
Posting Yak Master
154 Posts |
Posted - 2010-06-07 : 11:14:36
|
Hello.I have a dataset that looks basically like this:Date Absenteeism1/1/2010 202/1/2010 303/1/2010 25etc.... As months progress into the future this table is updated. I need to write a SP that displays the last 12 months of data. So if it's June it needs to display June 2009-June 2010. If it's July it needs to display July 2009-July 2010. I hope that makes sense.I'm not sure how to do this. Someone suggested 12 selfjoins, but I don't know what that would look like. Help! Craig |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-06-07 : 11:17:01
|
| where date_col>=dateadd(month,datediff(month,0,getdate())-12,0) anddate_col<dateadd(month,datediff(month,0,getdate())+1,0) MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|