简体   繁体   中英

call a stored procedure from another stored procedure and bring values from first stored procedure to the second stored procedure

I am currently doing an assignment where I create a stored procedure "sp_master".

From that stored procedure, I read in the needed external data, internal data and then perform all the required logic to decided if the inputted information is valid.

I then need to call a stored procedure "sp_insert" from the "sp_master" stored procedure. From the "sp_insert" stored procedure I need to add a row to a table using the external data that was read into the "sp_master" stored procedure.

I know how to call a stored procedure from another stored procedure, but I am not sure how to bring the values across, which is what I need the help with

here is a snippet of my code to give an understanding

Create proc sp_master
 @DeliveryID int, @FreightID int, @NoOfGoods int
as
--Perform reads and logic
begin
EXECUTE sp_Insert_delivery
end

then from sp_Insert

Create proc sp_exam_Insert_delivery
as
begin try
insert into dbo.Delivery
(FreightID, DeliveryID, NoOfGoods)
Values
(@FreightID, @DeliveryID, @NoOfGoods)
end try
--followed by catch

You just need to add the same parameters to sp_Insert_delivery and pass them in.

Create proc sp_master
 @DeliveryID int, @FreightID int, @NoOfGoods int
as
--Perform reads and logic
begin
EXECUTE sp_Insert_delivery @DeliveryID, @FreightID, @NoOfGoods
end

.

Create proc sp_Insert_delivery
  @DeliveryID int, @FreightID int, @NoOfGoods int
as
begin try
insert into dbo.Delivery
(FreightID, DeliveryID, NoOfGoods)
Values
(@FreightID, @DeliveryID, @NoOfGoods)
end try
--followed by catch

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM