passing one stored procedure o/p value to another stored procedure

Posted by Varung under Sql Server on 12/6/2011 | Points: 10 | Views : 1371 | Status : [Member] | Replies : 5
can u ppl please help me in passing one stored procedure o/p value to another stored procedure

G.Varun


Responses

Posted by: Sksingh on: 12/6/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,
use output parameter in called SP that will return some value and same value u could use as paramenter in calling SP.

Regards,
Sunil

Varung, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Varung on: 12/6/2011 [Member] Starter | Points: 25

Up
0
Down
but in my called sp i have insert query.....
k my requirement is
when i insert a record using sp,it should return the s.no of inserted record.....
where s.no is auto increment

G.Varun

Varung, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksingh on: 12/6/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

CREATE PROCEDURE AddCategory


-- Add the parameters for the stored procedure here

@Category NVARCHAR(15),

@CategoryID INT OUTPUT

AS

BEGIN

SET NOCOUNT ON;



-- Insert statements for procedure here

INSERT INTO Categories (CategoryName) VALUES (@Category)

SET @CategoryID = SCOPE_IDENTITY()

END


From above sp it will return CategoryID as recently inserted value that is auto increment value.
now this value u can use in calling SP.

Hope it will solve your issue.

Regards,
Sunil

Varung, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Varung on: 12/6/2011 [Member] Starter | Points: 25

Up
0
Down
i need it in mysql.....
this method will not work in mysql.....

G.Varun

Varung, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 12/13/2011 [Member] Silver | Points: 25

Up
0
Down
Hi you can use select top 1 identitity column name with order by desc option to the output variable which will be input for your 2nd procedure

Thanks,
Sanjay

Varung, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response