Solved

sum by year

Posted on 2014-11-25
2
158 Views
Last Modified: 2014-11-25
Below is a sample. I want it to return a sum of 2014 and a sum of 2013. I am not sure how to do it.

year 2014 = $110
year 2013 =$15
dif = $95


select

sum(case when year(DateShipped) = 2014 then (unit_dollar * QTYSHIPPED) else (unit_dollar * QTYSHIPPED)  end) as Incr2014

from table where year(qtyshipped) in ('2013', '2014')

Here is my sample data


id  Unit    qtyshipped  unit_dollar  DateShipped
1   watch    10         $100          2014-01-02 00:00:00.000
2   Pen      5          $10           2014-01-05 00:00:00.000
2   Notebook 3          $15           2013-01-05 00:00:00.000
etc
0
Comment
Question by:VBdotnet2005
2 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 500 total points
ID: 40465246
SELECT Year(dateShipped) Yr, SUM( qtyshipped  * unit_dollar  ) total
FROM yourTable
GROUP BY Year(DateShipped)
0
 

Author Comment

by:VBdotnet2005
ID: 40465309
Thank you
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

773 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