I know this question has been asked many times. I am just trying to verify that my solution is correct.
I need to concatenate a column values with the rows being ordered on another column.
I initially used the FOR XML PATH clause for the purpose, and it worked wonders, until I had XML entities (&, < etc) in my data, and FOR XML PATH encoded those. After some searching on experts-exchange, I came up with the following code for myself:
SET @freeFieldXml = '';
SELECT @freeFieldXml = @freeFieldXml + '/' + Value FROM @fields ORDER BY CodeType;
SET @freeFieldXml = STUFF(@freeFieldXml, 1, 1, '');
In my testing, the above code worked perfectly. I just want to confirm that the data would always be sorted on the desired column and the concatenated string would actually have the field values sorted by that column.
I always think tomorrow will have more time than today. And every today seems to pass-by
View Complete Post