Avatar of Éric Moreau
Éric Moreau
Flag for Canada

asked on 

MS SQL Read XML value by key name

I have a XML field in a column in a MS SQL table. 


I am trying to read the value of <updated key="Rule"> which sometimes is shown first, other times second (and other times just not at all!).


Here is an example of my field:

DECLARE @options XML = '<ID>1673671</ID><LastUpdate>2018-10-24 14:05:37.143</LastUpdate><updated key="Directory">+Role+Symbol+</updated><updated key="Rule">+Parameter+</updated>'

SELECT @options.value('updated[1]', 'varchar(1000)')  AS ModicationDetails1

SELECT @options.value('updated[2]', 'varchar(1000)')  AS ModicationDetails2

Open in new window

XMLMicrosoft SQL Server

Avatar of undefined
Last Comment
Éric Moreau

8/22/2022 - Mon