?
Solved

sum by year

Posted on 2014-11-25
2
Medium Priority
?
167 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
[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
2 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 2000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

800 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