March 28, 2011 at 2:23 pm
you should be able to get what you want using the dateadd function(http://msdn.microsoft.com/en-us/library/ms186819.aspx)
this should get you started
select DATEADD(qq,-2,getdate()),DATEADD(qq,-1,getdate()),GETDATE(),DATEADD(qq,1,getdate()),DATEADD(qq,2,getdate())
March 28, 2011 at 3:29 pm
Hi Bob , Thanks for your time , I know DATEADD Provides this , But Can you help how can i incorporate this in my SQL given .
Raje
March 29, 2011 at 1:33 pm
I am unable to edit your provided sql because I have no idea about table structure or data contained within. Read the link in my signature on how to post to get the best possible help.
That being said, something like this might work for you.
select cast(year(datecol) as char(4))+'Q'+cast(DATEPART(qq,datecol) as CHAR(1)) as [Quarter],
col2,
col3
from Table1 T1
Join Table2 T2 on t1.colx=t2.coly
where datecol >= DATEADD(qq,-2,getdate())
and datecol <= DATEADD(qq,2,getdate())
group by
cast(year(datecol) as char(4))+'Q'+cast(DATEPART(qq,datecol) as CHAR(1)),
col2,
col3
If you would like a more precise example please read the link and provide ddl, sample data, and desired output.
Viewing 3 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply