Avoid returning result set from stored procedure
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.
精彩评论