Couple of points to make...
1. If
iznos_bpdv
etc need to store numeric data, make them columns of a numeric type on the table. Always store data in the appropriate column type.
2. The SUM function will rationalise NULL values anyway so there is no need for
IsNull
nor
Coalesce
within the function call.
3. If every single entry on the table (that match the
Where
criteria) are
Null
then the
SUM
will return
Null
, so you can put the
IsNull
on the
outside of that function call as demonstrated in this code snippet
declare @tab table (x int null)
insert into @tab values (null), (null), (null)
select sum(x) from @tab
select isnull(sum(x),0) from @tab
4.
Isnull
is marginally faster than
Coalesce
if you only have the two options i.e.
select isnull(sum(x),0) from @tab
select coalesce(sum(x),0) from @tab