开发者

Avoid returning result set from stored procedure

开发者 https://www.devze.com 2023-01-08 14:22 出处:网络
Ass开发者_如何学Goume I have some stored procedure (and I can\'t change it) which is returning a result set:

Ass开发者_如何学Goume I have some stored procedure (and I can't change it) which is returning a result set:

create procedure test_procedure
as
begin

    select 1

end

I know that I can insert result set into table, so it would be hidden to the calling code:

declare @t table(i int)

insert into @t
exec test_procedure

Are there any other ways to hide returning result set from the calling code?

Updated

It looks like I've been a bit confusing. I'm looking only for T-SQL answers (not .NET ones).


No, there is no other solution. However, you should refactor your procedure to do only what you need. If you need the output for other calls, try to split the procedure into two.


Use optional Output Parameter.

or use below case

Create procedure Check @c int
as
begin
if @c = 1
    select 1
else
    print 1 
end

write any condition that will satisfy and that returns you specified values. use that parameter as optional so no other change in your procedure will come.


Would you rather try to return your data through an output parameter, and return a status code as the procedure's return value?

You couldn't easily return a full resultset through that output parameter, but you could return some delimited data in a format of your choosing.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号