How to Call a stored procedure from another stored procedure?

偶尔善良 提交于 2019-12-30 04:25:05

问题


I have an insert stored procedure which takes many parameters - 2 of them are @FirstName, @LastName. I also have an update stored procedure which takes many parameters - 2 of them are @FirstName, @LastName.

What I want to do is, from inside the insert SP, when it's done, call the update SP and send to it the @FirstName, @LastName.

I don't know the right syntax to do that; I tried:

exec  LandData_Update @FirstName, @LastName

But I think it's wrong.

Can someone tell me how to write this calling?

And if I will call the update sp with different param names? Such as @MyFirstName, @MyLastName? Would I write it like this: EXECUTE LandData_Update @MyFirstName=@FirstName, @MyLastName=@LastName?


回答1:


What makes you think it's wrong?

CREATE PROCEDURE MyInsertSP
    @FirstName varchar(255),
    @LastName  varchar(255)
AS
BEGIN
    INSERT INTO Table VALUES('Some Value')

    EXECUTE LandData_Update @FirstName, @LastName
END

Do you get an error or something?

EDIT: It doesn't matter what the name of the variables are, but to do what you want you can declare two new variables.

DECLARE @MyFirstName varchar(255)
DECLARE @MyLastName  varchar(255)

SET @MyFirstName = @FirstName
SET @MyLastName  = @LastName

And then use the new variables. But again, the Store Procedure doesn't care what the variables are called.



来源:https://stackoverflow.com/questions/1184325/how-to-call-a-stored-procedure-from-another-stored-procedure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!