怎样在存储过程里判断Select语句是否有记录?谢谢

解决方案 »

  1.   

    if EXISTS(select * from 表名)
       begin
        
       end
      

  2.   

    declare @ll int
    select @ll=count(*) from table
    if @ll>0 then
       select "有记录"
    end if
      

  3.   

    if exists(select * from table)
      

  4.   

    use CY
    go 
    if exists(select name from sysobjects where name= 'lpy' and type='p') **********
    drop procedure lpy
    go
    create procedure lpy 
    @money int
    as 
      select * from Cgongzi where 底薪>=@money
    order by 底薪 desc
    go 一个最简单的存储过程  ********  是你想要的部分
      

  5.   

    @@rowcount.就是select后影响的记录个数
      

  6.   

    @@ROWCOUNT
    返回受上一语句影响的行数
      

  7.   

    应该用EXISTS,如果要取得select的行数就没办法要用@@rowcount
    但是用exists的问题少,昨天刚解决了一个用@@rowcount出错的问题,解决方法就是改用EXISTS