0

I have a stored procedure that performs some processing and returns a bunch of output parameters. I want to call the stored procedure just for the processing, and don't really care about the output parameters. Is there any way to call the stored procedure without having to declare variables for all the output parameters?

In case this isn't clear... I don't want my stored procedure call to have to look like this:

DECLARE @param1, @param2, @param3 float
DECLARE @param4, @param5 datetime
DECLARE @param6, @param7, @param8, @param9 int
etc.,etc.
EXEC MyStoredProcedure @param1 OUTPUT, @param2 OUTPUT, @param3 OUTPUT, @param4 OUTPUT.......

I want to be able to just say:

EXEC MyStoredProcedure

Is there any way to specify "I don't care about output parameters - ignore them"?

froadie
  • 79,995
  • 75
  • 166
  • 235

2 Answers2

4

If the parameters in the SP have default values, they do not have to be passed in.

Oded
  • 489,969
  • 99
  • 883
  • 1,009
  • @froadie - If you set a default value to the parameter (`INPUT` or `OUTPUT`), you don't have to state it. – Oded Jul 14 '11 at 09:08
  • 1
    Yes, OUTPUT params can have default values, etc. See my answer and give it a go... – MatBailie Jul 14 '11 at 09:08
  • got it, thanks... and I guess there's no way to override it just for one single stored procedure call? – froadie Jul 14 '11 at 10:03
  • @froadie - Not if it doesn't have defaults. Values are required for parameters. – Oded Jul 14 '11 at 10:04
3
  CREATE PROCEDURE test (@id INT = 0 OUTPUT)
  AS
  BEGIN
    SELECT @id = @id + 1
    SELECT @id
  END
  GO;

  DECLARE @x INT
  SET @x = 9
  EXEC test @x OUTPUT
  SELECT @x
  EXEC test @x
  SELECT @x
  EXEC test
MatBailie
  • 83,401
  • 18
  • 103
  • 137