Solved

capture data for each quarter

Posted on 2014-03-06
6
359 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
  • 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 12

Accepted Solution

by:
Harish Varghese earned 500 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 Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
SQL Query Syntax Error 9 33
c# code 19 59
Copy Database Wizard Error 3 20
Convert int to military time 8 20
If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now