Solved

sum by year

Posted on 2014-11-25
2
152 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

747 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

11 Experts available now in Live!

Get 1:1 Help Now