--如果没有满足条件的,返回的是null--测试
declare @a int
select @a=max(id) from sysobjects where xtype='a'
select @a--结果: NULL

解决方案 »

  1.   

    declare @a int
    select @a=max(id) from sysobjects where xtype='a'
    if @a = null
    begin
    print '111'
    end
    else
    begin
    print '222'
    end但是在和null比较时,是不同的....
      

  2.   

    NULL 值表示列的数据值未知或不可用
    当搜索的列中包括定义为允许空值的列时,可以通过下列模式查找数据库中的空值或非空值:WHERE column_name IS [NOT] NULLdeclare @a int
    select @a=max(id) from sysobjects where xtype='a'
    if @a is null
    begin
    print '111'
    end
    else
    begin
    print '222'
    end