代码之家  ›  专栏  ›  技术社区  ›  VoodooChild

bigint最小值的IsNull()?

  •  4
  • VoodooChild  · 技术社区  · 15 年前

    -9223372036854775808 而不是 123

    我从一个无法传递空参数的存储过程调用它

    declare @t bigint;
    set @t = -9223372036854775808;  --min value for bigint / long
    select ISNULL(@t, 123)
    
    7 回复  |  直到 15 年前
        1
  •  11
  •   OMG Ponies    15 年前

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

    负值并不意味着值为空。NULL表示完全没有任何值。

        2
  •  4
  •   tpdi    15 年前

    因为@t不是空的。

        3
  •  3
  •   bobs    15 年前

    ISNULL(@t, 123) 如果@t为NULL,函数返回123,否则返回@t。你可能想这样做。

    NULLIF(@t, -9223372036854775808)
    

        4
  •  2
  •   Neil Moss    15 年前

    要达到我认为你想要达到的目标,请尝试以下方法:

    declare @t bigint; 
    set @t = -9223372036854775808;  --min value for bigint / long 
    select ISNULL(NULLIF(@t, -9223372036854775808) , 123) 
    

    或者这个:

    declare @t bigint; 
    set @t = -9223372036854775808;  --min value for bigint / long 
    select case @t when -9223372036854775808 then 123 else @t end
    
        5
  •  1
  •   Mark Cidade    15 年前

    -9223372036854775808 IS NULL 这是不正确的。 ISNULL(@t, 123) 仅当 @t IS NULL 但它不是空的,因为它的值为 -9223372036854775808 它是非空的。

        6
  •  1
  •   Mark Schultheiss    15 年前

        7
  •  1
  •   dave    15 年前

    declare @t bigint;
    select ISNULL(@t, 123)