如何更新多个行以及每个已更新的行,在另一个表中插入一行。
伪示例:
update Table1
set CustQty = 20, set @UpdatedPk = PkRow
where Table1.customer_id = "A1233"
and Table1.CustQty < 20
insert into Table2 (Table1Pk) values (@UpdatedPk)
答案 0 :(得分:2)
使用OUTPUT
子句:
UPDATE Table1
SET CustQty = 20
OUTPUT INSERTED.PKRow INTO Table1PK
WHERE Table1.customer_id = "A1233" AND Table1.CustQty < 20