1

I have a query in a myTableAdapter that ends with WHERE column IN (@S). This works fine when I use myTableAdapter.Fill(dataset.table, "text") but I can't find any way that works to provide multiple text strings such as "text1, text2" for the IN parameter. How can this be done?

Daniel Daranas
  • 22,454
  • 9
  • 63
  • 116
John
  • 225
  • 9
  • 21
  • http://stackoverflow.com/questions/337704/parameterizing-a-sql-in-clause, look at the 2nd answer, it's better I think. – manji Apr 06 '11 at 16:41

1 Answers1

0

This is not possible as it stands as far as I know.

The alternative is to use dynamic SQL (i.e. generate the WHERE clause in code), but this is bad practice unless you really don't care about security, maintainability or readability!

The other extreme involves writing a table-valued function to live on the db server that accepts your @S parameter. This param should be a delimited string which you could then parse within the function using T-SQL WHILE and BEGIN ... END constructs, inserting each item from your string into a temp table.

Finally, your query's WHERE clause would then become something like:

WHERE myField in (SELECT myTempColumn from [dbo].[myParsingFunction] (@S))
Widor
  • 13,003
  • 7
  • 42
  • 64