Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2009-05-13 : 02:21:26
|
| Hello,I raised a query a little while ago regarding updating and replacing the values in an xml field but no one seems to know the answer.So here is the question in case someone is familiar with the solution.Basically the update query should replace the occurances of "&" to "&"I have only managed to do this one at a time and do not see how to run this query for all the records in the table.I have produced a sample for you below.Hope someone can help.Thank youdeclare @Sample table(ID varchar(50),UpdatedField xml,[xml] XML) INSERT @SampleSELECT 'x12345','<stringList xmlns="http://schemas.myCompany.com/myProject/[app]/stringList/1.0"><value>value1234</value></stringList>','<stringList xmlns="http://schemas.myCompany.com/myProject/[app]/stringList/1.0"><value>value1</value></stringList>' UNION ALLSELECT 'x4321', NULL,NULL UNION ALLSELECT 'x9876', '<stringList xmlns="http://schemas.myCompany.com/myProject/[app]/stringList/1.0"><value>valuex</value></stringList>','<stringList xmlns="http://schemas.myCompany.com/myProject/[app]/stringList/1.0"><value>value5</value><value>value2</value></stringList>' UNION ALLSELECT 'x6789', NULL,'<stringList xmlns="http://schemas.myCompany.com/myProject/[app]/stringList/1.0"><value>Alliance & Leicester Group Treasury plc</value><value>value1</value><value>value5</value><value>value2</value></stringList>' select * from @Sampledeclare @NewDescription varchar(1000)set @NewDescription = 'Alliance & Leicester Group Treasury plc'UPDATE A SET [xml].modify(' declare default element namespace "http://schemas.myCompany.com/myProject/[app]/stringList/1.0"; replace value of ((/stringList/value[.="Alliance & Leicester Group Treasury plc"]/text())[1]) with sql:variable("@NewDescription") ')FROM @Sample AS Awhere A.ID = 'x6789'SELECT * FROM @Sample |
|
|
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2009-05-13 : 07:28:25
|
| Hello again all,Apparently this is the limitation of xml in sql server (So I have been told) as modify works only for one value.Anyway, to do this you need to simply convert to varchar(max) whilst doing the update.Thanks anyway... |
 |
|
|
|
|
|
|
|