EbertB
EbertB

Reputation: 93

2 ISNULLS IN A SELECT

Is there a better way to do this or is this code ok?

DECLARE  @Test DECIMAL(18,2) = NULL
        , @Test1 DECIMAL(18,2) = '5'

SELECT ISNULL(@Test,(ISNULL(@Test1,'0')))

Thanks, EB

Upvotes: 1

Views: 35

Answers (1)

Lukasz Szozda
Lukasz Szozda

Reputation: 175606

There is no need for nesting ISNULL. You could use COALESCE:

Evaluates the arguments in order and returns the current value of the first expression that initially does not evaluate to NULL

DECLARE @Test DECIMAL(18,2) = NULL , @Test1 DECIMAL(18,2) = 5;
SELECT COALESCE(@Test, @Test1, 0);

DBFiddle Demo

Upvotes: 5

Related Questions