Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
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 May 24th, 2007, 08:44 AM
Authorized User
 
Join Date: Nov 2006
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to get value when procedure return value

Hi
my problem is related with procedure as well as function. Actually, I want to get return value from proc1 to proc2. For that I am giving u a very simple examle in steps....

Step 1: I have to create a proc sp1

create proc sp1 @p1 int,@p2 int
as
return @p1 * @p2

Step 2: Now i execute sp1 and created proc sp2

create proc sp2
as
declare @x int
set @x = sp1 5,6
print @x

or

create proc sp2
as
declare @x int
declare @y int
declare @z int
set @y=4
set @z=6
set @x = sp1 @y,@z
print @x


Step 3: I want to run that proc sp2

but it gives error : Incorrect syntax near '5'.

Pls Solve this problem.

Note : Here is not allowed to use OUTPUT parmameter

Thanks in advance
Kumar Ashish
krashishroa@yahoo.co.in
__________________
Thanks
Kumar Ashish
krashishroa@yahoo.co.in
 
Old May 28th, 2007, 05:16 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Code:
create proc sp1 @p1 int,@p2 int
as 
return @p1 * @p2
This is not the right way to return values. You got to use an output parameter for returning values from the procedure. Read BOL (Book Online) for using output parameter in Stored Procedures.

_________________________
- Vijay G
Strive for Perfection
 
Old May 29th, 2007, 11:30 AM
Authorized User
 
Join Date: Oct 2005
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You have to call the EXECUTE function to call an SP and here's how to retrieve the return value:

create proc sp2
as
declare @x int
EXECUTE @x = sp1 5,6
print @x

SQL Server Helper
How well do you know SQL? Find out with the free test assessment from SQL Server Helper!!!
http://www.sql-server-helper.com/free-test/default.aspx

Got a SQL Server Question? Ask us here: http://www.sql-server-helper.com/forums/default.asp





Similar Threads
Thread Thread Starter Forum Replies Last Post
[Resolved] Get return value from stored procedure snufse ASP.NET 2.0 Basics 1 August 8th, 2008 11:05 AM
Stored Procedure return value dmiles C# 3 December 6th, 2007 05:20 AM
how can i return a recrdset in a stored procedure? arathy ASP.NET 1.0 and 1.1 Basics 0 December 12th, 2006 04:24 AM
Can i return a recordset in a Stored procedure chiefouko VB Databases Basics 6 December 12th, 2006 03:34 AM
Can i return a recordset in a Stored procedure chiefouko SQL Server 2000 1 June 23rd, 2003 06:13 AM





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