Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2009

    Unanswered: Transfer value between stored procedures


    I have 2 stored procedures one where a record is entered in a table. In this proc the newly entered ID is found using scope_identity(). I have another proc that needs this value. Is there any way to pass it between them or should a function be created to store that value and requested by the 2nd proc?

  2. #2
    Join Date
    Aug 2009
    one approach can be to nest the second procedure in the first one .

    assign the scope_identity to a global variable and pass it along in both procedures.

  3. #3
    Join Date
    Jul 2009
    I prefer to have 2 separate procedures so that debugging is easier. I want to use a function to store the ID and then call it from the other procedure. I am new to TSQL syntax so any help on that? I have created the function as this:
    ALTER FUNCTION dbo.Function2 (@storeid int)
    RETURNS int
    	RETURN @storeid 
    1) Now my problem is how do I pass the @newStudentID from the procedure to this function. What is the syntax to be used? Was trying
    exec dbo.function2 @newStudentID. Will that pass the variable to the function?

    2) How do I call it in the other procedure?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts