Solved

sum - case statement

Posted on 2014-10-23
2
90 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
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 31

Accepted Solution

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

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Suggested Solutions

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.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

744 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

15 Experts available now in Live!

Get 1:1 Help Now