I have string data with xml format in "Input" column from which I need specific values of nodes.
As an example:
I need every "error_text_1" value from each "error id".
{
"xml" : "<?xml version='1.0'?>
<error_protokoll xmlns:SOAP-ENV.....>
<header>
<source>machine</source>
</header>
<error_list>
<error id='0'>
<error_text_1>error0</error_text_1>
</error>
<error id='1'>
<error_text_1>error1</error_text_1>
</error>
</error_list>
</error_protokoll>"
}
The following sql statement returns only the "error_text_1" value of id=0.
SELECT top (10)
XML_INPUT.value('(error_protokoll/error_list/error/error_text_1)[1]', 'varchar(200)') error
FROM
(
convert(xml, SUBSTRING( REPLACE(INPUT, '{
"xml" : "<?xml version=''1.0''?>', ''), 0 , len(REPLACE(INPUT, '{
"xml" : "<?xml version=''1.0''?>', ''))-3)) as XML_INPUT
FROM [Storage].[ods].[table]
) a
Please, see that I need to process first the "Input" column value to remove the "{}" brackets and the "xml" : ...xml version=''1.0..." part to have a correct xml structure.
This was the workaround to be able to get node value out of it.
Instead of only the first item, I'd like to have all of them.
Could you please help how to solve this?