gpt4 book ai didi

sql - 更新具有不同 id 的两个表的存储过程

转载 作者:行者123 更新时间:2023-12-04 18:33:29 26 4
gpt4 key购买 nike

我有这样的存储过程:

alter procedure [dbo].[delivary] @dedate nvarchar(100), 
@carid nvarchar(100),
@transid integer as
begin
select t.transactID
from Transaction_tbl t
where t.TBarcode = @carid
update Transaction_tbl
set DelDate = '' + @dedate + '', Status=5
where TBarcode = @carid
update KHanger_tbl
set Delivered=1
where transactid=@transid
end

我可以更新我的交易表。我还想用匹配 @caridTransactID 更新表 KHanger_table

我该怎么做?

最佳答案

有两种方法可以做到:

首先检索您的 transactID 并将其存储在变量中:

alter procedure [dbo].[delivary] @dedate nvarchar(100), 
@carid nvarchar(100)as
begin
declare @transid int
select @transid = t.transactID
from Transaction_tbl t
where t.TBarcode = @carid

update Transaction_tbl
set DelDate = '' + @dedate + '', Status=5
where TBarcode = @carid

update KHanger_tbl
set Delivered=1
where transactid=@transid
end

你有关系更新:

alter procedure [dbo].[delivary] @dedate nvarchar(100), 
@carid nvarchar(100) as
begin
update Transaction_tbl
set DelDate = '' + @dedate + '', Status=5
where TBarcode = @carid

update KHt
set KHt.Delivered=1
from KHanger_tbl as KHt
inner join Transaction_tbl t
on KHt.transactionid = t.transactID
where t.TBarcode = @carid
end

关于sql - 更新具有不同 id 的两个表的存储过程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17251510/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com