我有这样的存储过程:
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
我能够更新我的交易表。
我还想用匹配
KHanger_table
的TransactID
更新表@carid
。我该怎么做?
最佳答案
它应该是
alter procedure [dbo].[delivary]
(@dedate nvarchar(100),
@carid nvarchar(100))
AS
begin
DECLARE @transactID int;
SET @transactID = (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=@transactID
end
关于sql - 存储过程更新具有不同ID的两个表,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17251510/