Each field (we'll call it field1) has a concatenated string associated with it (we'll call it field2). I want to delimit field2 so the concatenated value break out into several rows. I'm using "Nodes" to accomplish this but I keep getting an error.
There are other methods to achieve this goal such breaking the string into columns and pivoting on the data but that's cumbersome. This method seems the most efficient but I don't quite know how to do it.
with xmll as (
select field1, cast('<r>'+replace(replace(field2,'Case #',''), ',', '</r>
<r>')+'</r>' as xml) as XMLCol
from [database].dbo.table i
where field2 like 'Case%#%'
)
select x.*
, n.r.value('.', 'varchar(max)')
from xmll x
cross apply
XMLCol.nodes(XMLCol) as n(r)
order by field1
The current error message is:
Msg 8172, Level 16, State 1, Line 1
The argument 1 of the XML data type method "nodes" must be a string literal.
What it is now:
What I want: