将执行SQL之后的结果放入临时表#temp中,
declare @a int
select @a=count(*) from #temp 
if @a>=1 
   ...
else
   ...

解决方案 »

  1.   

    就没别的办法么?
    能不能在 查询 数据之后 对查询到的数据进行处理 ?
    不是这种 count 的.
      

  2.   

    可以用@@rowcount来知道里边
    select @@rowcount来显示
      

  3.   

    可用@@RowCount判断受上一语句影响的行数。
                select * from xpxx Where id=@id   --查询数据            if @@RowCount = 0 -- @@RowCount:返回受上一语句影响的行数。
                  begin
                      --没有找到数据时插入新数据
                      Insert a_xpxx
                        (bc_id, qh, lbmc, no1, no2, no3, no4, no5)
                      Values 
                        (NEWID(),@qh, @lbmc, @no1, @no2, @no3, @no4, @no5)
                      Return 1  --插入成功
                  end
                else
                    --找到新数据时的操作
                    Return 0
      

  4.   

    哎~  我再加分....  
    这样不能读取记录呀...  我需要得到  查询返回记录中的 ID,NAME,URL 等几个字段的内容. 大侠看有办法么?
      

  5.   

    @@Rowcount 可以判斷,如果實在不行,用笨方法,用個 Exists 查詢吧
      

  6.   

    up我是要在SP 里面检测返回的数据 内容 . select TOP 1 @int_userid=id,[name],[url] from [dbo].[user] where name=@str_name and cat_id=@int_catid
    if @int_userid>0
    begin
    ..............
    end
    像这样的 无法执行 :(
      

  7.   

    create proc test
    (@a varchar)
    as
    select * from 表
    while @@rowcount >0 
    begin
      操作
    end;
    ---------------
    或者用游标
    -----------
    create proc test1(@a varchar(20))
    as
    begin
      declare csr CurSor for
      select * from 表
      open csr
      fetch next from csr into 变量
      while @@rowcount>0 
      begin
        判断
        fetch next from csr into 变量
      end;
      close csr
      deallocate csr
    end;
      

  8.   

    if exists(select 1 from 你的表 )
    begin
    …………
    end