'SQL Case statement with subtraction and avoiding a negative value
I have a SQL stored procedure with a case statement. The statement is taking a cost and adding to it for the specific ExtCostCategory.
However, for WHSE-BRDR this needs to subtract 0.05 from the cost. How can I write this to avoid a negative value if PriceUOMCost is less than 0.05?
update t
set PriceUOMCost = cast(case c.ExtCostCategory
when 'WHSE-VEND' then x.PriceUOMCost + 0.05
when 'WHSE-RETL' then x.PriceUomCost + 0.08
when 'WHSE-BRDR' then x.PriceUOMCost - 0.05
when 'VEND-BRDR' then x.PriceUOMCost + 0.05
else x.PriceUOMCost
end as decimal(10,3))
Solution 1:[1]
I don't know If I am missing something but can't you just do that?
when 'WHSE-BRDR' and x.PriceUOMCost >= 0.5 then x.PriceUOMCost - 0.05
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Anastasios Selmani |
