日期:2014-05-17  浏览次数:20447 次

如何控制不返回调用的嵌套存储过程中产生的集合
大概的例子就是这样,
sp_test2  比较复杂,不能改动,他会返回集合,同时输出值
在调用sp_test1  的时候也返回集合,但最后返回去前台就会有两个集合
目的:只想返回sp_test1  产生的集合,不要sp_test2 产生的,如何解决?
create table test(id int identity(1,1),code varchar(8)) 
insert into test select 'aaaa' union select 'bbbb' 
go 

create procedure sp_test2  
@id   int        output

as 
begin 
    select @id=id from test where code='aaaa' 
select @id 
end 
go 

create procedure sp_test1  
as 
begin 
    declare @id int
    exec sp_test2 @id out
    select @id as nid
end 
go 

exec sp_test1 
go 

drop procedure sp_test1,sp_test2 
drop table test 
存储

------解决方案--------------------
你的前台是指应用程序吧,在应用程序端控制呗
假设执行sp1返回了2个表集,那么在程序端就读取数据时只读取表集2就好了啊