I have a query in which I want to return all rows associated with a list of values. You can write this very simply:
select * from TableA where ColumnB in (1, 2, 3, 5)
I could generate this request in C # and execute it. However, this is clearly not ideal, since it does not use parameters, it will suffer when trying to cache query plans and is clearly vulnerable to an SQL injection attack.
An alternative is to write this as:
select * from TableA where ColumnB = @value
This can be done multiple times using C #, however this will result in N database hits.
The only alternative that I see is to create a temporary table and join it in this way, but I do not see this point of view in this, because it will be more complex and will have the same limitations as the first option.
I use SQL Server and OLDB, making a query is not a problem. I am trying to create the most efficient process.
Which of these three methods is more effective? Did I miss an alternative?
Liath source
share