count(*)当以某一条件查询时,无满足的记录,
我需要计算,所以需要它返回0,而且必须是数字的
帮忙

解决方案 »

  1.   

    select isnull(count(*),0) from tb
      

  2.   

    select isnull(count(*),0) from table
      

  3.   

    select '1' ID
    into #tempselect isnull(B.统计数,0) 统计结果 from #temp AA left join 
    (select ID,isnull(count(ID),0) 统计数 from dbo.Action group by ID) B
    on AA.ID=B.ID
    drop table #temp
      

  4.   

    select isnull(count(*),0) from table
    --------------------------
         不行 什么都没显示 我之前就是用的这个
    select   '1 '   ID 
    into   #temp 
    --------------------------
         不行 我不能修改别人的数据库
      

  5.   

    declare @a int
    select @a=count(*)
    from XX
    where XXif @a=null
    @a=0
    go
      

  6.   

    declare @a int
    select @a=count(*)
    from XX
    where XXif @a=null
    @a=0
    go
      

  7.   

    似乎用
    Select Count(*) From 表 where 条件
    当条件不满足时,返回结果就是0,没有必要用isNULL来转换!!楼主还是把自己的问题描述清楚些
      

  8.   

    declare @t table(id int)
    insert @t select 1select isnull(count(*),0) as [count] from @tdelete from @tselect isnull(count(*),0) as [count] from @t/*(所影响的行数为 1 行)count       
    ----------- 
    1(所影响的行数为 1 行)
    (所影响的行数为 1 行)count       
    ----------- 
    0(所影响的行数为 1 行)
    */
      

  9.   

    if not exists(select top 1 * from table where 条件)
        select [count] = 0
    else
        select [count] = count(*)from table 条件
      

  10.   

    当条件不满足时,返回结果就是0,没有必要用isNULL来转换
    比如下面语句就是返回0use northwind
    select count(*) from dbo.Customers
    where customerid='csdn'use northwind
    select count(*) from dbo.Customers
    where customerid='csdn'