Avoid returning result set from stored procedure

☆樱花仙子☆ 提交于 2020-01-03 07:06:26

问题


Assume 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).


回答1:


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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/3329777/avoid-returning-result-set-from-stored-procedure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!