Delete Multiple lines using Loop

How can I run through an array of ID's and delete the fields associated to it in a single table?  I have a lot of bad data that needs to be removed.  BTW, I'm using the SQL Server Management Studio to do this.

I'm currently doing by hand by using the following.

USE database;
DECLARE @id integer
SET @id = XXXXX

DELETE FROM table WHERE id = @id;

I would like to use the same code but with a slight variation to support an array.

August 31st, 2015 2:01pm

Where are you getting the array of IDs?
Free Windows Admin Tool Kit Click here and download it now
August 31st, 2015 2:39pm

How do you know the IDs of bad data? If you have an answer you should be able to write a query to delete them.
August 31st, 2015 2:42pm

Well right now I'm having to look through the table for the bad data and make a list.
Free Windows Admin Tool Kit Click here and download it now
August 31st, 2015 3:17pm

You can list your IDs in the following query:

DELETE FROM YourTable WHERE id IN (1, 2, 3, .

August 31st, 2015 4:39pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics