Sql server - Get last occurrence of an XML attribute -
i have following data in table
and i'm trying write query return row contains last occurrence of given id. example :- in case of example above, it'll return 2 rows (id#282 & id#266)
how go writing this?
with t1 (select *, xml.value(( '(//customer/@id)[1]' ), 'int') customerid yourtable), t2 (select *, row_number() on (partition customerid order id desc) rn t1) select id, customerid, xml t2 rn = 1
Comments
Post a Comment