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
 comparing list to a table

Author  Topic 

gwanin@gmail.com
Starting Member

1 Post

Posted - 2008-03-18 : 04:59:15
Hi guys, i'm sort of stuck.

I have a list of names, all i have to do is check to see if any of them are in a table, if they are they get deleted. The unique field of the table is title and it is what i have. I don't really know how i am meant to do this. I thought of creating a new table, placing my values into it and comparing to the already existing table, but surely their is a simple way?

readysetstop
Posting Yak Master

123 Posts

Posted - 2008-03-18 : 06:56:27
Nope. If you're going to 'compare' anything, it'll need to be in a table of some kind.

If this is a one-shot deal, try a temp table or table variable. If you're going to be doing this on a regular basis, create a permanent table for it.

____________________________________________________________________________________
"Believe in those who are seeking the truth. Doubt those who say they have found it." -Andre Gide
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-03-18 : 06:57:54
You can use IN operator to achieve this

DELETE FROM MainTable WHERE Title IN (your comma seperated list of titles)
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-03-18 : 06:59:55
http://www.sommarskog.se/arrays-in-sql.html

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -