1

In SQL Server, is an OUTPUT parameter actually an INPUT/OUTPUT parameter? I'm assuming this since even if we specify the OUTPUT keyword for a parameter in the stored procedure definition, we are still required to supply value for this parameter when calling a stored procedure.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
user702769
  • 2,435
  • 2
  • 25
  • 34

3 Answers3

2

Yes, you have to provide a value for the output parameter.

For example, of you create a stored procedure like this:

CREATE PROC sales_for_type @type VARCHAR(55), @total_sales INT OUTPUT
AS
SELECT SUM(qty) FROM sales a, titles b
WHERE
a.title_id = b.title_id
and
b.type = @type

and then you call it like:

DECLARE @total_sales_business int
EXEC sales_for_type business, @total_sales=@total_sales_business OUTPUT

Check this article.

TheBoyan
  • 6,802
  • 3
  • 45
  • 61
  • I assume when we call sales_for_type via "EXEC sales_for_type business, @total_sales=@total_sales_business OUTPUT", the value passed to @total_sales is Null?! Anyways, thank you both for your help – user702769 Jan 04 '12 at 19:13
1

Yes, an output parameter is also an input parameter.

Mikael Eriksson
  • 136,425
  • 22
  • 210
  • 281
0

Yes it is both input and output as others already answered. But in case you don't want to be forced to give an input parameter, you can easily set a default value in the parameter declaration.
See also this question: Can I have an optional OUTPUT parameter in a stored procedure?

Community
  • 1
  • 1
Marc
  • 9,012
  • 13
  • 57
  • 72