Hi @Decompressor ,
Per my knowledge, you could modify below part since the procedure [dbo].[insmain] has 8 paramters which did not provided in below part.
exec insmain @guid output
I also tried from my side with some modifications and it was working.
You could refer below and check whether it is helpful.
CREATE OR ALTER PROCEDURE [dbo].[insmain]
@calendar datetime,
@inout char,
@cust varchar(10),
@tr_name nvarchar(50),
@tt_weight int,
@tr_type int,
@MainID int,
@tt_vin nvarchar(50),
@guid uniqueidentifier output
AS
begin
set nocount on
declare @table table(ItemID uniqueidentifier)
insert tx_main (calendar,inout,cust)
output inserted.uni into @table(ItemID)
values(@calendar,@inout,@cust)
set @MainID=SCOPE_IDENTITY()
insert tx_transport(MainID,calendar,tr_name,tt_vin,tt_weight,tr_type)values(@MainID,
@calendar,@tr_name,@tt_vin,@tt_weight,@tr_type)
select @guid=ItemID from @table
end
CREATE OR ALTER PROCEDURE [dbo].[insphoto]
@img_name nvarchar(50),
@photo varbinary(max),
@calendar datetime,
@calendar2 datetime,
@inout char,
@cust varchar(10),
@tr_name nvarchar(50),
@tt_weight int,
@tr_type int,
@MainID int,
@tt_vin nvarchar(50)
AS
begin
declare @guid uniqueidentifier
exec insmain @calendar2,@inout,@cust,@tr_name,@tt_weight,@tr_type,@MainID,@tt_vin,@guid output
insert fotoblock (img_name,photo,calendar,[guid])values(@img_name,@photo,@calendar,@guid)
end
Firstly, I inserted some sample data into [tx_main] table.
INSERT INTO [dbo].[tx_main] ([calendar],[inout],[cust]) VALUES
('2020-09-01 09:00:00','1','aa'),
('2020-10-07 09:00:00','2','bb'),
('2020-10-08 09:00:00','3','cc')
Then I would execute the procedure [insphoto] with all paramters provided.
exec [insphoto] 'ddd',13234554,'2020-10-02 08:00:00','2020-10-03 09:00:00','1','aaa','BB',1,1,1,'ABC'
Finally, I checked the result of all tables and found that the latest guid of tx_main table was sucessfully inserted into the fotoblock table.
select * from [tx_main]
select * from [tx_transport]
select * from [fotoblock]
Output:
Best regards
Melissa
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.