Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Help Deleting Multiple Lines in a Table

Author  Topic 

mtorbin
Starting Member

2 Posts

Posted - 2007-02-28 : 14:41:06
Hey all,

I know very simple SQL queries but I need help with this one. I have multiple lines in a SQL database that I need to run. Basically, I need to run this (the bracketed text and the XXX are place holders):

DELETE FROM [tableName] WHERE [columnName] = 'XXXXX'

But I need to run it around 90 times where XXXXX is a unique variable each time. I could create 90 lines similar to this one but that would take way too much time to run. Any suggestions for a noob?

Thanks,

- MT

-=<>=-=<>=-=<>=-=<>=-=<>=-
Matt Torbin
President
Center City Philadelphia Macintosh Users Group
http://www.ccpmug.org/

Kristen
Test

22859 Posts

Posted - 2007-02-28 : 14:43:59
Is this any good?

DELETE FROM [tableName] WHERE [columnName] IN ('XXXXX', 'YYYYYY', ...)

The alternative is to put all the values for [columnName] in a separate table, and JOIN to it - in order to identify the rows to be deleted

Kristen
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2007-02-28 : 14:55:34
The question is: where do those 90 xxxx values come from ?

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

mtorbin
Starting Member

2 Posts

Posted - 2007-02-28 : 15:28:55
quote:
Originally posted by Kristen

Is this any good?

DELETE FROM [tableName] WHERE [columnName] IN ('XXXXX', 'YYYYYY', ...)

The alternative is to put all the values for [columnName] in a separate table, and JOIN to it - in order to identify the rows to be deleted

Kristen



That's exactly what I wanted. To answer the other question, the values are given to me from an assistant. They are things that would have to be found by hand. Thanks for the quick reply.

- MT

-=<>=-=<>=-=<>=-=<>=-=<>=-
Matt Torbin
President
Center City Philadelphia Macintosh Users Group
http://www.ccpmug.org/
Go to Top of Page
   

- Advertisement -