Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
415 views
in Technique[技术] by (71.8m points)

sql - How to Call a stored procedure from another stored procedure?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...