我在做统计行数的时候,使用了count()函数,
还要把结果插入到另一张表中去
但是出现了
警告: 聚合或其它SET 操作消除了空值.
语句为:
select count(*) into B
from A 
请问如何解决?

解决方案 »

  1.   

    这是因为有的行的字段内容为 null 值,   
    聚合函数会忽略值为 null 的行,所以,count(*) 统计的值不含这些行在内。
      

  2.   

    那该如何忽略那些为null的字段,
      

  3.   

    declare @t table(ID int,[Name] varchar(10))
    insert @t select null,null
    insert @t select 1,null
    insert @t select null,'A'
    select count(isnull(id,0))[count] into  # from @t
    select count(id)[count] into  ## from @t
    select * from #
    select * from ##
    drop table #
    drop table ##(1 行受影响)
    count
    -----------
    3(1 行受影响)count
    -----------
    1(1 行受影响)
      

  4.   

    SET ANSI_WARNINGS Off;
    ---在語句前加入
    INSERT T SELECT COL...
      

  5.   

    在count()的时候,不计算空值的
      

  6.   

    select count(isnull(字段,'')) into B 
    from A 
      

  7.   

    cont()函数
    我不能确定表里是那个字段为null
    所以使用isnull()没有作用
      

  8.   

    select count(*) into B 
    from A
    where A.a >10 
    加上这个条件之后,
    如何使用isnull()
      

  9.   


    set ansi_warnings off
      

  10.   

    谢谢了
    问题解决了
    set ansi_warnings off 
    是对的