Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 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