I have a table variable called @workorders
, this table are filled by a query:
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
Then, what I want is to go through each record of the table @workorders
and delete a record with the value of the current record.
The table where I want to delete the records is called WorkOrders
, this table have a column called id_workorder
, for example:
Assuming the table variable @workorders
have 3 records:
- OT-001-16
- OT-002-16
- OT-005-16
I need to implement a kind of while loop, to get each record on the table @workorders
and for each record delete on the table WorkOrders
where id_workorder
= @workorders (id_workorder VARCHAR(100))(Current record)
.