Solved

sum - case statement

Posted on 2014-10-23
2
96 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 65

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 500 total points
ID: 40402201
Just curious, can transnum = 'sent' without transid being 'send'?
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

752 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