Solved

sum - case statement

Posted on 2014-10-23
2
94 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 32

Accepted Solution

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

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL replication over high latency link 10 61
LTrim & Double Space Correction 5 42
Query for timesheet application 3 20
SQL Quer 4 23
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

820 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