Can EXEC store a T-SQL stored procedure with an output parameter when ignoring a SELECT statement?

I call one stored procedure from another, and the procedure I call has an output parameter. Then I pass the output value to a local variable. This is good and good, but the problem is that there is also an operator in this procedure select, so when I exec, the results of the procedure are returned in the final set of results.

Is there a way to just get the value of the output parameter and ignore everything else?

+3
source share
2 answers

Although technically yes, you should not do this. The engine consumes resources to get a result that you ignore. You can also cause excessive competition. If you do not need a set of results, you need another procedure that should only generate the desired result.

+6
source

I'm sure there are some tricks for this, but the obvious solution that comes to mind is:

INSERT INTO #my_rubbish_temp_table_that_i_CREATEd_earlier
  EXEC dbo.mySproc @a, @b, @c OUTPUT

... according to the Remus reaction, this is a waste of the processor, I / O, etc.

If you can add an extra parameter to your stored procedure that allows you to suppress the result set, this will be great.

+4
source

All Articles