question

kafkaesque avatar image
kafkaesque asked

Can anyone explain this nested ISNULL to me?

The table is empty . I run this query and it returns 1, I'm not sure why. the max function can be changed to AVG() or MIN() and it still returns 1. Can anyone explain how this works?

SELECT ISNULL(max(ISNULL(CID,0)),+1)
FROM [dbo].[Test_Test]

t-sqlisnull
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Jon Crawford avatar image
Jon Crawford answered

ISNULL returns the first non-null value. Since your table is empty, it doesn't matter how you aggregate the column, the value returned will be NULL. Therefore your second condition (+1) is returned.

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

kafkaesque avatar image kafkaesque commented ·

thanks

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.