I have an nvarchar(max) column that contains the following xml code:
I need my query to retrieve the text in square brackets after the last CDATA. "Insufficient verification" in the example above. I am inexperienced with XML so I am not sure how to handle this in my query.
The column is called Comments so I have
SELECT n.comments
FROM Notes n
I don't think I can use a substring because the text will not always be "Insufficient Verification" but the result I want is always the text in square brackets after the last CDATA.
;with src
as
(
select code, user, cast(comments as xml) as comments
from notes
)
SELECT c.query('data(val1)') as comments,
r.code,
p.user
FROM src n
INNER JOIN reason r ON n.code = r.code
INNER JOIN person p ON p.user = n.user
CROSS APPLY comments.nodes('xmlPanelData/field') x(c)
WHERE r.code LIKE 'QC%'