Re: Updating XML documents stored within SQL Server

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



"Crookie74" <crookie74@xxxxxxxxxxx> wrote in message news:0ac3bc26-4883-48c0-bcc3-3dc0690faf65@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I have xml documents stored inside sql server. I know how to get back
a piece of data using xquery eg:

select CustomerDocument.query('data(/*:Customer/CustomerInformation/
Name)')
from Customer
where ID = '4747345041'

(This will return Pete)

but i don't know how to change the value. I was expecting something
like:

update Customer
set CustomerDocument.query('data(/*:Customer/CustomerInformation/
Name)') = 'Paul'
where ID = '4747345041'

but this doesn't work. Can someone please help me with the correct
syntax.

Thanks in advance
You need to use the modify method however SQL Server 2005 doesn't directly support dynamic updates. This means that you can set the value to 'Paul' if you know in advance it will be 'Paul' but not if you need to retrieve the value at run time. For that you'll need to use modify with dynamic SQL. See these links and if you are still struggling tell us more.

http://msdn2.microsoft.com/en-us/library/ms190675.aspx

http://www.devnewsgroups.net/group/microsoft.public.sqlserver.xml/topic55693.aspx


--

Joe Fawcett (MVP - XML)
http://joe.fawcett.name


.



Relevant Pages

  • Re: same application on multiple schemas
    ... As for the "comparison" with Sql Server, it was not intended to ask ... why Oracle does "not" support sql server behaviour:) I know oracle (I ... For every customer that will use our application, ... will use schema "SchemaA" ...
    (comp.databases.oracle.server)
  • Re: same application on multiple schemas
    ... As for the "comparison" with Sql Server, it was not intended to ask ... why Oracle does "not" support sql server behaviour:) I know oracle (I ... For every customer that will use our application, ... will use schema "SchemaA" ...
    (comp.databases.oracle.server)
  • Re: Modeling/Constraint question
    ... there are no duplicates in the keys; ... Enter: the surrogate key. ... there is a customer number. ... SQL Server community, why should believe anything else you say? ...
    (comp.databases.ms-sqlserver)
  • Re: same application on multiple schemas
    ... As for the "comparison" with Sql Server, it was not intended to ask ... why Oracle does "not" support sql server behaviour:) I know oracle (I ... For every customer that will use our application, ... will use schema "SchemaA" ...
    (comp.databases.oracle.server)
  • Re: Index for username/password
    ... say that users want to be able to define customer ... A username in a login table is a little different. ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ...
    (comp.databases.ms-sqlserver)