In C#, I have an array of integers, that represent the primary keys of rows in a Table in SQL Server. I need to select all these rows from SQL Server by executing a single Select command - preferably through a stored procedure.
There may be from a few to hundreds of ID's in the array, and the solution needs to work on SQL Server 2005 and 2008.
What is the best/most efficient way to do this ?
I currently have a solution, where I pass a string containing a comma-separated list of the ids to SQL Server, and then generating a SELECT statement based on this. I am hoping there is a better way, that do not involve dynamically generating the SQL statements.