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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Simple Update

Author  Topic 

salmonraju
Yak Posting Veteran

54 Posts

Posted - 2008-01-11 : 15:28:58
Hi, I have a table that stores xml string as data,this xml string contains all the information about user. Ex:
<UserData>
<UserLogin>raju<UserLogin>
<UserId>1<UserId>
<UserDetails>
<fname>sal<fname>
<lname>raju<lname>
<state/>
<country>Aus<country>
<UserDetails>
<UserData>
this above xml is stored as varchar in table like below

Id UserXml CreateDate
1 <UserData><UserLogin>raju<UserLogin>... 10/12/2008

i want simple query that updates all my records in the table where
country = Aus to Australia in xml,(i.e modifing the country tag in xml if Country=Aus to <Country>Australia<Country>

jhocutt
Constraint Violating Yak Guru

385 Posts

Posted - 2008-01-11 : 15:43:17
update table set UserXml = replace(UserXml, '<country>Aus</country', '<country>Australia</country')


"God does not play dice" -- Albert Einstein
"Not only does God play dice, but he sometimes throws them where they cannot be seen."
-- Stephen Hawking
Go to Top of Page

salmonraju
Yak Posting Veteran

54 Posts

Posted - 2008-01-11 : 16:04:54
Sorry,I am getting the following error

Argument data type text is invalid for argument 1 of replace function.

one more thing my UserXml is not Varchar ,it is text
Go to Top of Page

Jeff Moden
Aged Yak Warrior

652 Posts

Posted - 2008-01-12 : 22:37:25
Lookup "Modifying ntext, text, or image Values" in Books Online for an example. Has nothing to do with XML...

Heh... you've done two things I'd never allow anyone to do in my database... use a TEXT column and store raw XML in the database. Don't ask why... you just found out why ;-)

--Jeff Moden
Go to Top of Page
   

- Advertisement -