Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parameter returned from stored procedure

Status
Not open for further replies.

VBAHole22

Programmer
Nov 7, 2002
41
US
I know there is a way to get a parameter back out of a stored procedure I just don't have the sin tax right. Can anyone help me out?


Alter Procedure ReturnIDfromCommonName

@COMMON_NAME varchar(50),
@ID char(6) OUTPUT
As


SELECT @ID =BOVA
FROM BOVA_TAXONOMY
WHERE COMMON_NAME = @COMMON_NAME


/* set nocount on */
return
 
VBAHole22,
check SQL Server Books Online under "Returning Data Using OUTPUT Parameters".

The syntax is something like:

CREATE PROCEDURE get_sales_for_title
@title varchar(80), -- This is the input parameter.
@ytd_sales int OUTPUT -- This is the output parameter.
AS

-- Get the sales for the specified title and
-- assign it to the output parameter.
SELECT @ytd_sales = ytd_sales
FROM titles
WHERE title = @title

You would call it like this:

EXECUTE get_sales_for_title
"Sushi, Anyone?", @ytd_sales = @ytd_sales_for_title OUTPUT

And use it like this:

PRINT 'Sales for "Sushi, Anyone?": ' + convert(varchar(6),@ytd_sales_for_title)
GO

I hope this helps.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top