if select count(*) from tablename  > 0
print 'test'======
select count(*) from tablename的值是5,但是和0比较报错,如何在sql语句里面写这样的比较?在线等,马上结贴!

解决方案 »

  1.   

    if (select count(*) from tablename)  > 0 
      

  2.   

    if (select count(*) from tablename)  > 0
    print 'test' 
      

  3.   

    if (select count(*) from tablename)  > 0
    print 'test' 
      

  4.   

    if (select count(*) from tablename)  > 0 
    print 'test' 
      

  5.   

    if (select count(1) from tablename)  > 0 
      

  6.   

    HAHAif (select count(0) from tablename)  > 0 
      

  7.   

    select count(0) from tablename  这是个表查询得出值 
    在IF后面需要加括号 把它包起来,
    如果是单值 则不需要
      

  8.   

    select count(0) from tablename  是个整体
      

  9.   


    if (select count(*)from tablename) > 0
      

  10.   

    declare @a table(rq varchar(8), ddsj int)
    insert into @a
    select
    '200805',30 union all select
    '200805',40 union all select 
    '200805',50 union all select 
    '200805',20 union all select 
    '200806',250 union all select
    '200806',200 union all select
    '200806',310 union all select
    '200806',100 union all select
    --'200806',300 union all select
    '200806',130;select (select count(*) from @a where rq=t.rq and ddsj<=t.ddsj)as num ,* 
    into #t from @a t order by ddsjselect
     t.* 
    from
     #t t ,

    select 
    (min(num)+max(num))/2 num,
    ceiling((min(num)+max(num))*1.0/2)num1,rq 
    from 
    #t 
    group by rq)as t1 where (t.num=t1.num or t.num=t1.num1) and t.rq=t1.rqnum         rq       ddsj        
    ----------- -------- ----------- 
    2           200805   30
    3           200805   40
    3           200806   200(所影响的行数为 3 行)