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 2005 Forums
 Transact-SQL (2005)
 to CASE or not to

Author  Topic 

yosiasz
Master Smack Fu Yak Hacker

1635 Posts

Posted - 2009-03-12 : 15:24:01
Greetings

I have the following 4 variables:
@length , @width , @gauge , @Density

I need to do the following calculation
@length * @width * @gauge * @Density
But width and gauge could have values of 0
Instead of having this huge indented CASE statement how could I do the calculation using boolean validation if @width @gauge are both 0 or if @width or @gauge is zero
@length * @width * @gauge * @Density

Thank you

Bodestone
Starting Member

18 Posts

Posted - 2009-03-12 : 17:23:46
Not sure exactly what you mean by the boolean validation. Just taking a punt that you want to multiply all the non 0 numbers.
Still using case but not nested:
SELECT @length * CASE @width WHEN 0 THEN 1 ELSE @width END * CASE @gauge WHEN 0 THEN 1 ELSE @gauge END * @Density
Go to Top of Page
   

- Advertisement -