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 2005 Forums
 Transact-SQL (2005)
 How do I do a REPLACE on a text field

Author  Topic 

icw
Constraint Violating Yak Guru

378 Posts

Posted - 2009-02-07 : 00:50:33
Hi
I have a text field (Gdetail) in a table (Heatgen)that contains filepaths in amongst other info

e.g. '[Info] NumAttachments=1 [Attachments] Attachment1=Water lilies.jpg|C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Water lilies.jpg'

The attachments have all been moved to a new folder so i need to update the database to change 'C:\Old Folder\' to 'P:\New folder\'

The replace function would be ideal - if it worked on a text field.
is there an alternative for a text field

icw
Constraint Violating Yak Guru

378 Posts

Posted - 2009-02-07 : 01:08:22
Hi
i just figured this out. it seems to work. can anyone confim please that i am right to do this...

SELECT REPLACE(Cast(HeatGen.GDetail as varchar(max)), 'C:\Old', 'P:\New')
FROM HEATGEN
WHERE HEATGen.GCode = 'AT'
Go to Top of Page

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-02-07 : 01:40:32
Ok, I think its work fine
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-07 : 08:19:39
quote:
Originally posted by icw

Hi
i just figured this out. it seems to work. can anyone confim please that i am right to do this...

SELECT REPLACE(Cast(HeatGen.GDetail as varchar(max)), 'C:\Old', 'P:\New')
FROM HEATGEN
WHERE HEATGen.GCode = 'AT'



replace wont work with text datatype. you need to use this

http://www.sqlteam.com/article/search-and-replace-in-a-text-column
Go to Top of Page
   

- Advertisement -