-1

I have say a table, the columns of which will contain integer value but i am not sure if they may contain NULL too. Now lets say I want to add the integers, (along with any NULL) to get the result as an integer even when any column in between is NULL.

I am aware of the ISNULL() function and COALESCE() function. But i would prefer not to use any of these. Nor i want to use CASE. I know that CASE would do what i want, but I am looking for something more better.

Just like we have CONCAT_NULL_YIELDS_NULL to ensure that when a string is concatenated to a null value, the result is not null.

I want something similar to this option. Thanks in advance.

vstandsforvinay
  • 138
  • 1
  • 11

2 Answers2

1

You should probably just use those functions. Assuming you can't:

SELECT SUM(MyIntCol) --filters out NULLs automatically

SELECT CASE WHEN MyIntCol IS NOT NULL THEN MyIntCol ELSE 0 END --default value 0
usr
  • 168,620
  • 35
  • 240
  • 369
1

This isn't really an answer to you but it might be a solution for people running MS SQL Server 2012 or newer.

SELECT IIF(<NullableColumn1> is null, 0, <NullableColumn1>)
+ IIF(<NullableColumn2> is null, 0, <NullableColumn12) ...
FROM <YourTable>

But I assume, that the engine will do the same what is done, when there is CASE used instead.

schlonzo
  • 1,409
  • 13
  • 16