--创建测试环境
create table tupian
(
id int,
isdel bit,
isshow bit
)
insert tupian
select 1,1,1 union
select 2,0,1 union
select 3,0,1
gocreate proc sp_test
@p int=10,
@pc int=0 output
as
declare @sql nvarchar(1000)
declare @pcc int
select @pcc=count(1) from tupian where isdel=0 and isshow=1
set @pc=@pcc
set @sql='select top '+cast(@p as nvarchar(20))+' id from tupian where isdel=0 and isshow=1'
exec(@sql)
return @pcc
go--测试
declare @n int,@count int,@returnValue int
select @n=5
exec @returnValue=sp_test @n,@count outputselect [返回值]=@returnValue,[输出参数]=@count--删除测试环境
drop table tupian
drop procedure sp_test--结果
/*
id
-----------
2
3(2 row(s) affected)返回值 输出参数
----------- -----------
2 2(1 row(s) affected)
*/
create table tupian
(
id int,
isdel bit,
isshow bit
)
insert tupian
select 1,1,1 union
select 2,0,1 union
select 3,0,1
gocreate proc sp_test
@p int=10,
@pc int=0 output
as
declare @sql nvarchar(1000)
declare @pcc int
select @pcc=count(1) from tupian where isdel=0 and isshow=1
set @pc=@pcc
set @sql='select top '+cast(@p as nvarchar(20))+' id from tupian where isdel=0 and isshow=1'
exec(@sql)
return @pcc
go--测试
declare @n int,@count int,@returnValue int
select @n=5
exec @returnValue=sp_test @n,@count outputselect [返回值]=@returnValue,[输出参数]=@count--删除测试环境
drop table tupian
drop procedure sp_test--结果
/*
id
-----------
2
3(2 row(s) affected)返回值 输出参数
----------- -----------
2 2(1 row(s) affected)
*/
create proc sp_test
@p int=10,
@pc int=0 output
as
declare @sql nvarchar(1000)
declare @pcc int
select @pcc=count(1) from tupian where isdel=0 and isshow=1
set @pc=@pcc
set @sql=N'select top '+cast(@p as nvarchar(20))+' id from tupian where isdel=0 and isshow=1'
exec sp_executesql @sql
return @pcc
go
declare @pc int
exec sp_test 50,@ppc output
select @ppc --因为还是会返回数据集,那么在下面可以看到返回值已经存在了!如果用的是return,调用时候必须是:
declare @pc int
exec @ppc = sp_test 50 ----output指不指定没有关系
select @ppc
如果变量用了output,,就不需要用return来返回了!! 直接把return改成select
--直接把return改成select??直接set @pc=@pcc,返回值本来就不需要在grid里面秀出来啊!
这个SP是想测试是否RETURN 和 OUTPUT 是否都没返回
但是发现在SQL查询分析器可以PRINT出东西但是在ASP中通过adodb.COMMAND的EXECUTE 之后。 就得不到返回了。 最后只好用 SELECT @PC 返回第二个结果集。 我还是想知道如果OUTPUT 或者 RETURN 的话该怎么办呢?