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
 General SQL Server Forums
 New to SQL Server Programming
 returning a value from a stored procedure

Author  Topic 

BendJoe
Posting Yak Master

128 Posts

Posted - 2008-01-22 : 11:56:16
I have a Sproc shown below I want the procedure to return the New_ID value back to the calling program how can I do this.
The current approach is not working. Please help.
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
.................................
ALTER PROCEDURE [dbo].[SP]
(
@Id int=NULL ,
@site_id int = null,
@Date datetime = null,
)
AS
BEGIN
Declare @New_ID varchar(10)
EXEC [dbo].[SP_GENERATEID] @New_ID output
INSERT INTO A_Table(
CODE,INT_ID,SITE_INT_ID,DATE,
)
Values
(
@New_ID,@Id,@site_id,@Date )
return @New_ID
END
Thanks


visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-01-22 : 12:00:35
Add a new OUTPUT param as NewID and use it to return the generated id.Cant understand why you are inserting new id value.Can you explain what you are trying to achieve?
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-01-22 : 12:03:22
Declare @New_ID as output parameter and return it from SP. See more about using output parameter in SQL server help. Otherwise you can simply replace Return by SELECT statement like:

SELECT @New_ID



Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

BendJoe
Posting Yak Master

128 Posts

Posted - 2008-01-22 : 12:09:30
Thanks
SELECT @New_ID is working for me.
Good Day.
Go to Top of Page
   

- Advertisement -