I have created one procedure which has one parameter VARCHAR(100). This procedure contains the parameter having value like '1,5,6,20'. The requirement is: Update the records having ID = 1,5,6,20 (Any of them). This is the one way that we can prepare the SQL query.
Convert VARCHAR variable to XML as follows:
So this statement will generate XML from VARCHAR value as follows:
So, Now this is the XML, which can be easily read in SQL SERVER (2005 and above) as:
This will give me result set as ( as a separate table)
So that’s it, Now I can easily use this result set in my query, to update the rows accordingly.
So my Procedure looks like:
So, it is very easy to read values from Comma separated value.
Let me know if it helps you.
Posted by Tejas Shah on November 22, 2017
Posted by Tejas Shah on November 11, 2017
Posted by Tejas Shah on August 12, 2015
Posted by Tejas Shah on June 26, 2015
Posted by Tejas Shah on April 20, 2015