我有一个名为@workorders
的表变量,该表由查询填充:
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
然后,我想要的是遍历表@workorders
的每个记录并删除具有当前记录值的记录。
我要删除记录的表名为WorkOrders
,此表有一个名为id_workorder
的列,例如:
假设表变量@workorders
有3条记录:
我需要实现一种while循环,以获取表@workorders
上的每条记录以及表WorkOrders
上的每条记录删除id_workorder
= @workorders (id_workorder VARCHAR(100))(Current record)
答案 0 :(得分:3)
您不能简单地INNER JOIN
@workorders
声明中的DELETE
表吗?
DELETE w
FROM workorders w INNER JOIN @workorders tw ON w.id_workorder = tw.id_workorder