Say I have this subset of data. All I need to do is have John | John | 20 as my output. The main issue I am having is that my XmlData is stored in an nvarchar(Max) field and the update to fix this, breaks an unknown amount of other applications (talking a massive scale so I cannot simply modify the table design).
Name nvarchar(23) | XmlData (nvarchar(max) |
John |<Personal><name>John</name><age>20</age></Personal> |
Suzy |<Personal><name>Suzanne</name><age>24</age></Personal> |
etc...
What I have tried so far is similar to the following, but it fails.
SELECT Name,
[myTable].Value('(Personal[name ="name"]/value/text())[1]', 'nvarchar(100)') as 'XmlName',
[myTable].Value('(Personal[name ="age"]/value/text())[1]', 'nvarchar(100)') as 'XmlAge'
FROM [MyTable]
How can I achieve my goal of the following output?
Name | XmlName | XmlAge |
John | John | 20 |
Suzy | Suzanne | 24 |
etc...