删除由table中的记录数给出的记录数

Delete a number of records given by the number of records in a table

我有一个名为 @workorders 的 table 变量,这个 table 由查询填充:

DECLARE @workorders table
(id_workorder VARCHAR(100));
INSERT INTO @workorders SELECT DISTINCT(id_workorder) FROM CampaingControl WHERE id_campaing = @id;
--get each record of the table @workorders and delete of another table

然后,我想要的是遍历[=​​39=] @workorders的每条记录,并删除具有当前记录值的记录。

我要删除记录的table叫WorkOrders,这个table有一个叫id_workorder的列,例如:

假设table变量@workorders有3条记录:

我需要实现一种 while 循环,以获取 table @workorders 上的每条记录并删除 table WorkOrders 上的每条记录,其中 id_workorder = @workorders (id_workorder VARCHAR(100))(Current record).

你能不能在你的 DELETE 语句中简单地 INNER JOIN @workorders table?

DELETE w 
FROM workorders w INNER JOIN @workorders tw ON w.id_workorder = tw.id_workorder