Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Output parameter

Author  Topic 

Sun Foster
Aged Yak Warrior

515 Posts

Posted - 2009-09-02 : 12:18:06
I want to learn store procedure but I still do not know how to use output parameters in a store procedure.
For example, there is one store procedure as I copied from a book:

create proc ytd_sales
@title varchar(80), @ytd_sales int output
as
select @ytd_sales=ytd_sales
from titles
where title = @title
return

How to use the result from this store procedure for another store procedure?

Ifor
Aged Yak Warrior

700 Posts

Posted - 2009-09-02 : 12:43:26
[code]
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
CREATE PROCEDURE dbo.ytd_sales
@title varchar(80)
,@ytd_sales int OUTPUT
AS

SET NOCOUNT ON

-- ensure an error if title is not unique and NULL if no title.
SET @ytd_sales =
(
SELECT ytd_sales
FROM titles
WHERE title = @title
)
GO

DECLARE @sales int

EXEC dbo.ytd_sales 'Your Title', @sales OUTPUT

SELECT @sales

EXEC dbo.AnotherProc @sales
[/code]
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-09-02 : 12:59:10
also see
http://www.sqlteam.com/article/stored-procedures-returning-data
Go to Top of Page
   

- Advertisement -