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 |
Simon_L
Starting Member
32 Posts |
Posted - 2008-11-28 : 12:51:59
|
HiIm using the following code to "replace" a value in a textstring that contains XML...It completes but replaces nothign as the final select shows... Ive got to get this workign on Monday so any help happily recieved !thanks si--create temptable subsetSELECT * into #user_messageFROM user_messagewhere messageXML like '% %'goalter table #user_messageadd rowid int identity (1,1)goDECLARE @ptrmessageXML varbinary(16), @rowid int, @otxt varchar(40), @ntxt varchar(40), @txtlen int, @StartingPosition intSET @rowid = 1SET @otxt = ' 'SET @ntxt = ' 'SET @txtlen = LEN(@otxt )WHILE @rowid <= 2BEGIN SET @StartingPosition = 2 SELECT @ptrmessageXML = TEXTPTR(messageXML) FROM #user_message WHERE rowid = @rowid WHILE @StartingPosition > 0 BEGIN SELECT @StartingPosition = CHARINDEX(@otxt , messageXML) - 1 FROM #user_message where rowid = @rowid IF @StartingPosition > 0beginUPDATETEXT #user_message.messageXML @ptrmessageXML @StartingPosition @txtlen @ntxtend END SET @rowid = @rowid + 1END SELECT *FROM #user_messagewhere messageXML like '% %'drop table #user_messagego |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-28 : 13:03:35
|
Is messageXML text field? what are two variable @otxt & @ntxt for? |
|
|
Simon_L
Starting Member
32 Posts |
Posted - 2008-11-28 : 13:25:15
|
messagexml is the text field, otxt is old text and ntxt is new text .. in the exmaple above their empty but I want to replace say user with <user> |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
|
|