Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 108
  • Last Modified:

sum - case statement

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
VBdotnet2005
Asked:
VBdotnet2005
1 Solution
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
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
 
awking00Commented:
Just curious, can transnum = 'sent' without transid being 'send'?
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now