Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 24th, 2006, 10:21 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default Output Parameters

Hello,

How do I call the following proc from Query Analyzer? Something like:

EXEC procOutGetCustomer 'ALFKI', ?, ?, ?

The proc is:

CREATE PROCEDURE procOutGetCustomer(
    @CustomerID nchar(5),
    @CompanyName nvarchar(40) OUTPUT,
    @ContactName nvarchar(30) OUTPUT,
    @ContactTitle nvarchar(30) OUTPUT)
AS SELECT
    @CompanyName = CompanyName,
    @ContactName = ContactName,
    @ContactTitle = ContactTitle
FROM
    Customers
WHERE
    CustomerID = @CustomerID
IF @@ROWCOUNT = 1
    RETURN 0
ELSE
    RETURN -1;

Thanks,

Bob



 
Old March 25th, 2006, 05:26 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

You need to decalre variables to receive the output and specify that they are of type OUTPUT:
Code:
DECLARE @CompanyName NVARCHAR(40) 
DECLARE @ContactName NVARCHAR(30)
DECLARE @ContactTitle NVARCHAR(30) 
EXEC procOutGetCustomer 'ALFKI', @CompanyName OUTPUT, @ContactName OUTPUT, @ContactTitle OUTPUT
PRINT 'CompanyName: ' + @CompanyName
PRINT 'ContactName: ' + @ContactName
PRINT 'ContactTitle: ' + @ContactTitle
--

Joe (Microsoft MVP - XML)
 
Old March 25th, 2006, 06:32 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

Thanks, Joe. Much appreciated.

Bob






Similar Threads
Thread Thread Starter Forum Replies Last Post
Output Parameters: I can't be this stupid... raysot BOOK: Professional SQL Server 2005 Integration Services ISBN: 0-7645-8435-9 13 May 20th, 2010 07:28 PM
Chapter 6 "Using SQL Output Parameters..." burkecrosby BOOK: Professional SQL Server 2005 Integration Services ISBN: 0-7645-8435-9 22 February 10th, 2010 05:33 PM
output parameters with the objectdatasource trancehead ASP.NET 2.0 Professional 2 August 25th, 2008 12:41 PM
OUTPUT Parameters saulodet ADO.NET 0 May 14th, 2004 10:02 AM
SQL output parameters ohiggs SQL Server 2000 4 February 9th, 2004 10:09 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.