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]
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]
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.
20 People are following this question.