XML columns compare in SQL Server -
i have got 3 columns:
- [oldcontent] [xml] null
- [newcontent] [xml] null
- [oldcontent] [xml] null
i want compare data in 2 columns. want write results third column ([oldcontent]
)
how can in sql server?
[oldcontent] [xml] null, in
value
<row guest_id="13" guest_name="vedat" guest_surname="pala" adress="izmir" />
[newcontent] [xml] null, in value
<row guest_id="13" guest_name="vedat35" guest_surname="pala" adress="izmir" city="dr" city_code="35" />
i want write value in it.
[updatecontent] [xml] null <row guest_name="vedat35 city="dr" city_code="35" />
i need procedure compare xml column values.
it quite easy data out of xml. may compare data "as ever". result can write out new xml "for xml".
try this:
declare @myxml xml= '<rows> <row guest_id="13" guest_name="vedat35" guest_surname="pala" adress="izmir" city="dr" city_code="35" /> <row guest_id="14" guest_name="testguestname" guest_surname="testsurname" adress="testaddr" city="testcity" city_code="11" /> </rows>'; --this how retrieve data select x.y.value('@guest_id','int') ,x.y.value('@guest_name','varchar(max)') ,x.y.value('@guest_surname','varchar(max)') ,x.y.value('@adress','varchar(max)') ,x.y.value('@city','varchar(max)') ,x.y.value('@city_code','int') @myxml.nodes('/rows/row') x(y) --this how create new xml data select 13 [@guest_id] ,'newname' [@guest_name] ,'newsurname' [@guest_surname] ,'newaddr' [@guest_adress] ,'newcity' [@city] ,12 [@city_code] xml path('row'),root('rows')
Comments
Post a Comment