SQL Server Performance Forum – Threads Archive
I’am doing a test case where i want to know in a numeric column as eg. below
to apply any aggregate function like sum() do i need to write like sum(isnull(Col1,0)) or just sum(Col1) as SQL server will automatically ignore the NULLS.
What generated my doubt here is when i use to do database applications before i use to code like sum(isnull(Col1,0)) as i had faced live problems returning NULLS in calculation but now it seems to be working fine, can anyone explain me is there any type of settings or other things are there which can put light on this. Mat
I don’t think you need to check the NULL… I think you will get the same value if you use ISNULL or not…
By default NULL is excluded from any calculation of an aggregate function. The only exeption here is COUNT() as COUNT(*) will also count NULL, while COUNT(expression) will ignore NULL. So, you should be safe even without using ISNULL. —
Microsoft SQL Server MVP
Also if you use col1+col2 where one of them is NULL then the result would be null Madhivanan Failing to plan is Planning to fail