Query on field of type XML – Top-level attribute nodes are not supported

Question : Query on field of type XML – Top-level attribute nodes are not supported  declare @x xml set @x = ‘ Ae> Jim Joe Be> Sally George> ‘ select t.c.query(‘./UserName’).value(‘.’,’varchar(20)’) , t.c.query(‘../CompanyName’).value(‘.’,’varchar(20)’) from @x.nodes(‘/root/Company/User’)as t(c) This query works, but How would I get the ID attribute from the company element in the result set as well,  my attempts lead to the following error: ‘ XQuery [value()]: Top-level attribute nodes are Continue Reading →