Solved

sum by year

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

Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

Question has a verified solution.

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

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.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

734 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