Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 On behalf of Maya_Zakry

Author  Topic 

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-01-23 : 01:19:45
quote:
Originally posted by maya_zakry

hello, can someone fix my multiple case statement..

SELECT col1, col2 from tblOne

CASE
WHEN (substring(d.StorageStatus,1,1)='H') THEN
Sum(d.HoldQty)
WHEN (substring(d.StorageStatus,1,1)='Q') THEN
Sum(d.QCQty)
ELSE
sum(ISNULL(d.OriginQty,0))-sum(ISNULL(d.HoldQty,0))- sum(ISNULL (d.QCQty,0))- sum(ISNULL(d.BookQty,0))- sum(ISNULL(p.PickQty,0)) AS BalQty END

AS BalQty

WHERE blablah
is this multiple case allowed?


NO!

But if you are trying to sum up different columns depening on some status column, try this
select		col1,
col2,
sum(case
when d.storagestatus like 'h%' then isnull(d.holdqty, 0)
when d.storagestatus like 'q%' then isnull(d.qcqty, 0)
else isnull(d.originqty, 0) - isnull(d.holdqty, 0) - isnull (d.qcqty, 0) - isnull(d.bookqty, 0) - isnull(p.pickqty, 0)
end) as qty
from tblone
group by col1,
col2
order by col1,
col2


Peter Larsson
Helsingborg, Sweden

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-01-23 : 01:32:36
huh


KH

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-01-23 : 01:43:14
Maya deleted the topic the second before I posted my suggestion.
And I thought the question and suggestion was valuable enough for more users to learn from.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-01-23 : 02:52:13
Of all the posts to pad in all the forums in all the world, you have to pick on Maya_Zakry?
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-01-23 : 03:02:39
Even if he walked into SQLTeam bar?

The question still remain, why he wold not let other people benefit from the question and answer, as he has himself been helped numerous times before?


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -