Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Getting current quarter & 4 previous quarters data
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

mihirvb84
Starting Member

11 Posts

Posted - 02/07/2018 :  15:20:16  Show Profile  Reply with Quote
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

USA
4 Posts

Posted - 04/18/2018 :  15:34:12  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000