SQL Server: Dynamic where-clause

You have two options. If you’re using SQL Server 2008 (or Oracle) you can pass in a table value parameter.

If you’re using SQL Server 2005, you can use XML to simulate this capability

If you’re using something earlier than 2005, you need to concatenate the ids in a single string and create a UDF to parse them.

Leave a Comment