I have a SQL query.
SELECT convert(xml, A.[business_line]).value('(/collection/object/fields/field/value)[1]', 'varchar(3)')
from [EU_OTH_REG].[dbo].[TBL_EU_OTH_TXN_REG_RSDS] A
I am getting an error while running this query.
Error states
Msg 9413, Level 16, State 1, Line 1
XML parsing: line 1, character 30, A string literal was expected
A.business_line has 2 set of values.
1) <collection><object parentid="ce57cc75-3966-478f-bf25-5e3abf716f96" parenttype="Object"><fields><field name="code"><value>BL3</value></field><field name="code"><value>BL2</value></field><field name="code"><value>BL5</value></field><field name="code"><value>BL1</value></field><field name="code"><value>BL6</value></field></fields></object></collection>
2) <collection><object parentid="ce57cc75-3966-478f-bf25-5e3abf716f96" parenttype="Object"><fields/></object></collection>
Can anyone help me on this?
A.[business_line], depending on how many rows you have you may be able to do that manually using an online XML validator, or you may need to find some automated way to do it. Unfortunately no one will be able to tell you what is wrong without seeing the data.declare @Test...to test both of those, what do you get?