Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

sum - case statement

Posted on 2014-10-23
2
Medium Priority
?
105 Views
Last Modified: 2014-10-30
Can I convert a sample from # 1 to #2.

#1
select
sum(QTYSHIPPED) AS QTY_SHIPPED

from

(

select

case when (TRANSNO='OUT' And TRANSID='PROCESS WIP') then TRANSCOUNT
when (TRANSNO='OUT' And TRANSID= 'SEND' And TRANSNUM= 'SENT') then TRANSCOUNT
else 0
end  AS QTYSHIPPED

from my table


# 2

select

sum(case when (TRANSNO='OUT' And TRANSID='PROCESS WIP') then TRANSCOUNT
when (TRANSNO='OUT' And TRANSID= 'SEND' And TRANSNUM= 'SENT') then TRANSCOUNT
else 0
end) AS QTY_SHIPPED

from my table
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 66

Expert Comment

by:Jim Horn
ID: 40400181
Yes.  What's the question?

There's an articled called SQL Server CASE Solutions that is an image and code-rich tutorial of the SQL Server CASE statement.  Scroll down to 'CASE can also be used with aggregates' for aggregate value examples.
0
 
LVL 32

Accepted Solution

by:
awking00 earned 2000 total points
ID: 40402201
Just curious, can transnum = 'sent' without transid being 'send'?
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

715 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