小弟刚刚接触存储过程
select count(*) from tablename我要返回count(*) 怎么实现QQ:280600958  感谢

解决方案 »

  1.   

    create proc test  as
    declare @count int
    select @count=count(*) from tablename
    select @count
    go
      

  2.   

    --也可以这样,借用楼上的代码 :)
    create proc test  
     @count int OUTPUT
    as
    declare @count int
    select @count=count(*) from tablename
    godeclare @count int
    exec test @count OUTPUT
    select @count
      

  3.   

    create proc test  
     @count int OUTPUT
    as
     select @count=count(*) from tablename
    godeclare @count int
    exec test @count OUTPUT
    select @count
      

  4.   

    create table test(id int)
    insert into test select 1 union select 2
    gocreate procedure sp_test(@count int output,@tabname nvarchar(100))
    as
    begin
        declare @s nvarchar(4000)
        set @s=N'select @count=count(*) from '+@tabname
        exec sp_executesql @s,N'@count int out',@count out
    end
    godeclare @cnt int
    exec sp_test @cnt out,'test'print @cntdrop procedure sp_test
    drop table test