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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Getting current quarter & 4 previous quarters data

Author  Topic 

mihirvb84
Starting Member

11 Posts

Posted - 2018-02-07 : 15:20:16
I am trying to build SQL query which pulls order value of a customer and the order value of same quarter but of prior year from the same customer. Can someone please explain the SQL format with an example I should follow?

---------------
Mihir Borde

sambosley
Starting Member

4 Posts

Posted - 2018-04-18 : 15:34:12
SELECT DATEPART(QUARTER,GETDATE()) AS [QUARTER], DATEPART(YEAR,GETDATE()) AS [YEAR],SUM(CUST_VALUE)
UNION
SELECT DATEPART(QUARTER,GETDATE()) AS [QUARTER], DATEPART(YEAR,GETDATE())-1 AS [YEAR],SUM(CUST_VALUE)

Samuel Bosley
Go to Top of Page
   

- Advertisement -