Link to home
Start Free TrialLog in
Avatar of datatechcorp
datatechcorpFlag for United States of America

asked on

MSSQL Sum w/NULL Column Values

HELLO!

I have a table called "POSTING" with the following values:

EVENT_NO                 AMT         DROP        LOAN
-----------------------------------------------------------------
E-1000117      0.00      NULL      NULL
E-1000117      668.49      -1500.00      NULL
E-1000117      393.80      NULL      NULL
E-1000117      1309.00      NULL      NULL
E-1000117      0.00      NULL      NULL
E-1000117      0.00      NULL      NULL
E-1000117      0.00      NULL      NULL

What I need to achieve...is something like the following:

Select Sum(AMT - DROP + LOAN) as NET_DAILY_TOTAL

However, of course, since there are many 'NULL' values in the DROP and LOAN columns, this will yield a total of 'NULL'...which is erroneous and nonsense.  Please let me know the correct Syntax to handle the 'NULL' values in the example above.  Thank You!...Mark
Avatar of Simone B
Simone B
Flag of Canada image

Try this, it should replace your NULLs with 0's then add them.

SELECT SUM(AMT - ISNULL([DROP],0) + ISNULL(LOAN,0)) AS NET_DAILY_TOTAL
SOLUTION
Avatar of Beartlaoi
Beartlaoi
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of datatechcorp

ASKER

Thank you both *SO* much for responding!  I truly appreciate it...this worked great!

Thanks!...Mark