Wednesday, March 28, 2012

Is there a NulToZero for SQL Server

I'm creating a view with an expression:

Sum(PayAmt)-TotalExpenses

If expenses are null it returns null, but I want it to return the Sum of PayAmt if the expenses are null.

If FRED is a nullable integer (or currency or decimal) column in table FRED

SELECT COALESCE(FRED, 0) FROM BERT

Will return 0 if FRED has a null value in given column, thus your SQL could be re-written as

Sum(COALESCE(PayAmt, 0))-TotalExpenses

Now you know the keyword you look it up in Books-On-Line

|||

TATWORTH,

Very Cool, AGAIN!

No comments:

Post a Comment