Sunday, June 28, 2015

work on xml

declare @data xml = '
<test>
    <tree abc="123"/>
    <tree abc="789"/>
    <tree-order abc="456"/>
</test>
'
select @data.query('<test>{for $i in test/* order by $i/@abc return $i}</test>').value('(/test/tree/@abc)[1]', 'varchar(200)') as [Info]
select Xdata.query('<test>{for $i in test/* order by $i/@abc return $i}</test>').value('(/test/tree/@abc)[1]', 'varchar(200)') as [Info] from testXMl order by id desc

insert into testXMl values('<test>    <tree abc="12"/>    <tree abc="14"/>    <tree-order abc="13"/></test>')

create table testXMl(Id int identity(1,1),Xdata XML )

No comments:

Post a Comment