Using a parameter for IN in a tableadapter query
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 f开发者_运维知识库ind any way that works to provide multiple text strings such as "text1, text2" for the IN parameter. How can this be done?
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))
精彩评论