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 |
spikyman
Starting Member
6 Posts |
Posted - 2013-02-10 : 03:25:14
|
Hi Guys!Can anyone resolve this job?I need to add another date option which would be the prior 12 months up through the last quarter. So if it were April 2013, I would see Mar 2012 to Mar 2013. If it were May 2013, I would see April 2012 to March 2013.Thank you for your help. |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-02-10 : 06:21:12
|
[code]--End of last quarterDATEADD(qq,DATEDIFF(qq,0,GETDATE()),-1)-- start of four quarters agoDATEADD(qq,DATEDIFF(qq,0,GETDATE())-4,0);-- to use this in a WHERE clause, I would use a slightly different approach -- as shown in red below:WHERE YourDateCol >= DATEADD(qq,DATEDIFF(qq,0,GETDATE())-4,0) AND YourDateCol < DATEADD(qq,DATEDIFF(qq,0,GETDATE()),0)[/code] |
|
|
spikyman
Starting Member
6 Posts |
Posted - 2013-02-10 : 11:00:58
|
Thank you very much ! |
|
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-02-10 : 11:27:23
|
You are very welcome - glad to help. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
|
|
|
|