I have a XML file which is something like this
declare @X XML
Set @X ='<A>
<B>
<C>161</C>
<D>190</D>
<E>43 ,44 ,48 ,49</E>
</B>
<B>
<C>162</C>
<D>190</D>
<E>100</E>
</B>
</A>
'
I want to parse it into a table:
C D E
161 190 43
161 190 48
161 190 49
162 190 100
I tried using
select
x.r.value('(A)[1]', 'int') as C,
x.r.value('(D)[1]', 'int') as D,
x.r.value('(E)[1]', 'varchar(max)') as E
from
@X.nodes('/A/B') as x(r)
DECLARE @xml as xml, @str as varchar(100), @delimiter as varchar(10)
SET @str = '43,48,49'
SET @delimiter = ','
SET @xml = cast(('<X>'+replace(@str,@delimiter ,'</X><X>')+'</X>') as xml)
SELECT T.N.value('.', 'int') as value FROM @xml.nodes('X') as T(N)
for separating the comma-separated column E into table.
But I am not able to combine both these in one query i.e. parse it into the table