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
 SQL Server 2012 Forums
 Transact-SQL (2012)
 additional case

Author  Topic 

magmo
Aged Yak Warrior

558 Posts

Posted - 2014-06-18 : 10:32:24
Hi

I have the following piece of Query


ISNULL(SUM(CASE WHEN NULLIF (TID, '0') IS NULL THEN Qty END), 0) AS QtyBooks



This works fine when TID is null or '0', but I also need to add (TID = ''), how do I add that check?

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-06-18 : 10:42:37
what about:


select isnull(sum(Qty), 0) AS QtyBooks
from ...yourtable...
where TID in ('0', '')
Go to Top of Page

magmo
Aged Yak Warrior

558 Posts

Posted - 2014-06-18 : 10:52:36
I cant do that beacuse I have Another condition almost like the one I posted that do Another Count. I Think I need to have the condition within the exsisting one....
Go to Top of Page

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-06-18 : 10:55:36
OK then:


ISNULL(SUM(CASE WHEN TID IN ('0', '') THEN Qty END), 0) AS QtyBooks
Go to Top of Page

magmo
Aged Yak Warrior

558 Posts

Posted - 2014-06-18 : 11:00:47
Awsome, thanks!
Go to Top of Page
   

- Advertisement -