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 2008 Forums
 Transact-SQL (2008)
 Using a CASE statement and checking for NULL value

Author  Topic 

Darts75
Starting Member

27 Posts

Posted - 2014-08-14 : 02:02:59
Hi Everyone,

I am using the CASE statement below (the commented section does not work, and it is the part that I need to remedy).



I am using the CASE statement below (the commented section does not work, and it is the part that I need to remedy).

Whilst the above works fine when looking for the value '0.00', and the responding output is correct, I also need to look for NULLs and respond accordingly. If anybody has any suggestions on how I can go about this it will be greatly appreciated.

Kind Regards,

David

ScottPletcher
Aged Yak Warrior

550 Posts

Posted - 2014-08-14 : 10:12:47
Change the first WHEN expression to include as ISNULL():

CASE WHEN ISNULL( CAST(...existing expression...), 0.00) = '0.00' THEN 'N/A'
ELSE ...
END
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2014-08-14 : 16:40:05
[code]CASE
WHEN t0.Stockvalue = 0 THEN 'N/A'
ELSE LTRIM(STR(100E * (t0.LineTotal - t0.StockValue) / t0.StockValue, 10, 2))
END[/code]


Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page
   

- Advertisement -