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