I am trying to parse a field based on a delimiter, in this case it is a '|'. Then, merge everything into other fields (Parse1, Parse2, etc.) in the same table. The code below seems to be pretty close, but it only parses correctly in my TempTable. For some reason, it does not update the Parse1, Parse2, Parse3, etc., in the FinalTable
SELECT DISTINCT
split.a.value ('/A[1]', 'VARCHAR(MAX)') [Piece1],
split.a.value ('/A[2]', 'VARCHAR(MAX)') [Piece2],
split.a.value ('/A[3]', 'VARCHAR(MAX)') [Piece3],
split.a.value ('/A[4]', 'VARCHAR(MAX)') [Piece4],
split.a.value ('/A[5]', 'VARCHAR(MAX)') [Piece5],
split.a.value ('/A[6]', 'VARCHAR(MAX)') [Piece6],
split.a.value ('/A[7]', 'VARCHAR(MAX)') [Piece7]
Field1,
Field2,
Field3
FROM [TempTable]
(
SELECT CAST('<A>' + REPLACE(SrcID, '|', '</A><A>') + '</A>' AS XML) AS Data, Field1, Field2, Field3
FROM dbo.FinalTable
) a cross apply Data.nodes('/A') AS split(a)
Does anyone have any idea what is wrong with this?