October 14, 2009 at 11:00 am
Hi!
I am working on a report and trying to calculate the previous 4 quarters from a given date. I need help! I am using Teradta SQL.
Thanks.
October 14, 2009 at 12:17 pm
the trick is to use the datediff and date add functions
for example here's how to find the first day of "this" quarter, ,and the previous 4 quarters based on today:
--First Day of the Quarter
select DATEADD(qq, DATEDIFF(qq,0,getdate()), 0)
--First Day of Previous Quarter
select DATEADD(qq, DATEDIFF(qq,0,DATEADD(qq,-1,getdate())), 0)
--First Day of two quarters ago
select DATEADD(qq, DATEDIFF(qq,0,DATEADD(qq,-2,getdate())), 0)
--First Day of three quarters ago
select DATEADD(qq, DATEDIFF(qq,0,DATEADD(qq,-3,getdate())), 0)
--First Day of four quarters ago
select DATEADD(qq, DATEDIFF(qq,0,DATEADD(qq,-4,getdate())), 0)
Lowell
October 14, 2009 at 12:31 pm
shilpa726 (10/14/2009)
Hi!I am working on a report and trying to calculate the previous 4 quarters from a given date. I need help! I am using Teradta SQL.
Thanks.
This forum is for questions about Microsoft SQL Server TSQL, not Teradata SQL.
It is not likely that that date manipulation functions from TSQL will work in Teradata SQL.
You should ask your questions on a Teradata site.
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply