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
 Easier way to delete specific records?

Author  Topic 

meef
Posting Yak Master

113 Posts

Posted - 2012-05-01 : 14:49:34
I need to delete 84 records and it's going to be a huge pain typing:

WHERE
name = 'this' OR name 'that' OR....

Is there any other way to delete or am I going to have to sit here and type it all out?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-05-01 : 14:52:17
you've to either do that or put the required values onto a temporary table and do like

DELETE t
FROM YourTable t
INNER JOIN TempTable tmp
ON tmp.field = t.name
WHERE .... any other conditions


where do you got these values from? is it already present in a master table field?
------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

meef
Posting Yak Master

113 Posts

Posted - 2012-05-01 : 14:55:12
Yeah, there are about 150 total records in a user account table and I need to delete 84 of them.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-05-01 : 15:45:48
quote:
Originally posted by meef

Yeah, there are about 150 total records in a user account table and I need to delete 84 of them.


get those 84 ids onto a table and use suggested query

other wise form a comma delimited list using 84 values and use dynamic sql

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -