Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IsNull() on bigint's min value?

Why does the following expression in SQL Server return -9223372036854775808 and not 123?

I am calling this from a stored proc where I can't pass null parameters

declare @t bigint;
set @t = -9223372036854775808;  --min value for bigint / long
select ISNULL(@t, 123)
like image 405
VoodooChild Avatar asked Nov 28 '22 19:11

VoodooChild


2 Answers

Because:

IF @t IS NOT NULL
  PRINT @t
ELSE
  PRINT 123

Being negative doesn't mean the value is NULL. NULL is the lack of any value at all.

like image 109
OMG Ponies Avatar answered Dec 01 '22 07:12

OMG Ponies


Because @t is not null.

What made you think that the most negative value for a bigint would be interpreted as null?

like image 35
tpdi Avatar answered Dec 01 '22 09:12

tpdi