I got a table which contains values like
1.<content><value>foo</value><value>bar</value></content>
2.<content><value>value3</value><value>value4</value></content>
I'm using the REPLACE Function, to remove all the Tags (content and value) and to seperate the values I replaced </value>
with ;
select CAST(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(CAST(TEXTVALUE as NVarchar(MAX))
,'<content>',''),'<value>','')
,'</value>',';')
,' ','')
,'</content>','')
AS NText) from dbo.mytable ...
The output of my select statement looks like this:
1.foo;bar
2.value3;value4
However - I would like to split this select statement to return a new row for each value:
1. foo
2. bar
3. value3
4. value4
I've seen lots of answers and methods to split the result of a select statement into multiple rows, but I didn't see any way to first replace part of the values and then split the result to multiple rows by character.
I hope you can help me out here.
EDIT: Thanks for so many helpful answers. I forgot to add, that I also would like to be able to select other columns within the same request.