I have Names table:
ID Name
1 Ken
2 John
3 Tom
…
I have following variable in c# code:
var names; //which is list of some names like “ken, Tom”
I need a query that goes through Names table and gets all names that are not in names variable.
So in above case if i run a query result should be John.
I am not sure how to write a query in this problem i am iterating through names and running query again and again and i think this is really bad way to do it. Can someone please suggest what is most efficient way to do this?
If you need to do it in T-SQL, you could do something like:
That could be done inline or in a stored procedure.
If you can use Entity Framework (you indicate .Net 4.0, so you should be able to), then you can use something similar to this answer:
Linq-to-sql Not Contains or Not in?