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.
-
yes, it is in-out, but you can easily test it out on your own.KM.– KM.2012-01-04 18:50:51 +00:00Commented Jan 4, 2012 at 18:50
Add a comment
|
3 Answers
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.
1 Comment
user702769
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
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?