?
Solved

capture data for each quarter

Posted on 2014-03-06
6
Medium Priority
?
392 Views
Last Modified: 2014-03-07
Hello experts,

I need to help with the following syntax.  I need to capture sales for the current Quarter and sales for the same quarter last year.

Current calender  Quarter : ?

Current calender   Quarter  Last year: ?
0
Comment
Question by:tips54
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 

Author Comment

by:tips54
ID: 39909882
0
 
LVL 12

Expert Comment

by:Harish Varghese
ID: 39909983
Please provide the structure of the tables.
0
 

Author Comment

by:tips54
ID: 39910005
Invoice_date           Customer_ ID               total_amount
1/1/13                      1                                   100
3/31/13                    1                                   500
4/1/13                       2                                  100
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 12

Accepted Solution

by:
Harish Varghese earned 2000 total points
ID: 39910194
Hello,
Select CurrentQuarterSales = SUM(case when Year(Invoice_Date) = YEAR(GetDate()) and Ceiling(month (Invoice_Date)/3) = Ceiling(month (GETDATE())/3) then Total_Amount Else 0 End),
	LastYearSameQuarterSales = SUM(case when Year(Invoice_Date) = YEAR(GetDate()) - 1 and Ceiling(month (Invoice_Date)/3) = Ceiling(month (GETDATE())/3) then Total_Amount Else 0 End)
From Sales

Open in new window

Group By CUstomer_ID if required.

-Harish
0
 

Author Comment

by:tips54
ID: 39912375
That did it. Thanks Harish.
0
 

Author Closing Comment

by:tips54
ID: 39912376
perfect.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question