Friday, February 24, 2012

Array in WHERE clause

Hello, how can I use an array in a WHERE clause?

If I had an array say

string[] NamesArray = new string[] {"Tom", "***", "Harry"}

How would I do this:

string myquery = "SELET name, city, country FROM myTable WHERE name in NamesArray"


Thanks in advance,

Louis

for a SQL Statement, you would need to serialize out the array of names into text (BTW that's "SELECT", not "SELET":

string myquery = "SELECT name, city, country FROM myTable WHERE name in ('george', 'jack', harry')

|||

Whatpbromberg wrote is correct, and here is another option which is also correct.

Insert you array items into a table (say MyArrayTable) and use this code:

1 SELET [name],2 city,3 country4FROM myTable5WHERE [name]in (6SELECT [Name]7 From MyArrayTable8 )9GO

Good luck.

|||

Thanks guys for your help.

It works,

Louis

No comments:

Post a Comment