Join on data from XML in T-SQL

brastyles

New Member
I have the following XML message:\[code\]DECLARE @XML AS XMLSET @XML = '<Message><Changes> <Deleted> <ROW id="1" name="Nicole" surname="Bartlett" city="denver" balance="779.4663" dateOfBirth="1991-12-11T14:05:42.830" maritalStatus="S" /> <ROW id="1" name="Nicole" surname="Bartlett" city="boston" balance="779.4663" dateOfBirth="1991-12-11T14:05:42.830" maritalStatus="S" /> </Deleted> <Inserted> <ROW id="1" name="Nicole" surname="Bartlett" city="denver" balance="779.4663" dateOfBirth="1991-12-11T14:05:42.830" maritalStatus="S" /> <ROW id="1" name="Nicole" surname="Bartlett" city="boston" balance="779.4663" dateOfBirth="1991-12-11T14:05:42.830" maritalStatus="S" /> </Inserted></Changes></Message>'\[/code\]And I need to select data from this message and join another table on id field. The following code doesn't work:\[code\]SELECT T.c.value('./@id', 'int') as id, t.c.value('./@name', 'varchar(max)') as name FROM @XML.nodes('/Message/Changes/Deleted/ROW') T(c)inner join other_table tbl on tbl.id = id\[/code\]How can I do this?
 
Back
Top