0% found this document useful (0 votes)
49 views

Stored Procedures With Parameters

The document describes how stored procedures can return output parameters and return values. It provides an example of a stored procedure that takes an input parameter of a title type and returns an output parameter of the total quantity sold for that type. The procedure is executed by declaring a variable to hold the output parameter and passing it to the stored procedure. A second example shows a procedure that selects a credit limit value into an output parameter based on a customer ID input parameter.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views

Stored Procedures With Parameters

The document describes how stored procedures can return output parameters and return values. It provides an example of a stored procedure that takes an input parameter of a title type and returns an output parameter of the total quantity sold for that type. The procedure is executed by declaring a variable to hold the output parameter and passing it to the stored procedure. A second example shows a procedure that selects a credit limit value into an output parameter based on a customer ID input parameter.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Stored Procedures - Output Parameters & Return Values

. The following procedure contains an input parameter of the title type and an output parameter of total quantity
of titles sold for the specified type:
1.
2.
3.
4.
5.
6.
7.

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

This procedure can be executed as follows:


1. DECLARE @total_sales_business int
2. EXEC sales_for_type business, @total_sales=@total_sales_business OUTPUT

Results:
1.----------2.90

OTRO EJEMPLO

create PROC limite_credito @id_cliente nvarchar,@limite int OUTPUT


AS
SELECT @limite=(SELECT limite_credito FROM cliente WHERE id_cliente
=@id_cliente)
GO
DECLARE @limite int;
EXEC limite_credito '001', @limite OUTPUT
print @limite

You might also like