Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

check if a value is NULL or Less than 0 in one TSQL statement

ISNULL(SUM(MyTable.Total), 0) AS Total

How can I modify the above statement to also check if Total is less than 0 (zero), such that If Total is NULL or less than 0 (negative), I assign 0 to Total

like image 444
StackTrace Avatar asked May 27 '10 10:05

StackTrace


1 Answers

CASE WHEN ISNULL(SUM(MyTable.Total), 0) <= 0 THEN 0
     ELSE SUM(MyTable.Total)
END AS Total
like image 150
lc. Avatar answered Nov 16 '22 23:11

lc.