This is hopefully just a performance optimization issue when it comes to queries in Sql 2008.
I worked for companies that reused Stored Procs for their ETL processes, as well as for some of their websites. I saw a scenario where they needed to get specific records based on a finite set of key values. I saw how it was processed in three different ways, illustrated using pseudo code below.
Dynamic Sql that concatenates a string and executes it.
EXEC('SELECT * FROM TableX WHERE xId IN (' + @Parameter + ')'
Using a custom function to split table-delimited rows
SELECT * FROM TableY INNER JOIN SPLIT(@Parameter) ON yID = splitId
USING XML as a parameter instead of a varchar separable value
SELECT * FROM TableZ JOIN @Parameter.Nodes(xpath) AS x (y) ON ...
Although I know that creating dynamic sql in the first fragment is a bad idea for a number of reasons, my curiosity comes from the last two examples. Is it more appropriate to do the due diligence in my code to pass such lists through XML, like in fragment 3, or is it better to just delimit the values and use udf to take care of this?
source share