1
Hello guys. I have a table with a TEXT field. I need to change information within this text field only that I am not getting. The REPLACE function works in a varchar field, but does not work within the text field.
For example: I have a record where this field contains the following information: "INFO:Alfa,Beta,Gama;CPPC-TM:0x3453;ALGOMAIS" I need to change this value "CPPC-TM" to "NEWINFO". The final resite should be: "INFO:Alpha,Beta,Gamma;NEWINFO:0x3453;ALGOMAIS"
There is a way to do this via sql?
I’ve tried to:
update MYTABELE
set orgsalkeyfil = replace(orgsalkeyfil, 'CPPC-TM', 'NEWINFO');
If I run the same script in a varchar field it runs smoothly.
If the column size is not too large, you can convert using CAST for
varchar
and then replace.– Valdeir Psr
If this is the case you can cast for (n)VARCHAR(MAX), just be careful to put a WHERE limiting the cases where the field does not exceed the size of the VARCHAR (were some 8k think), otherwise it will truncate the data. In NVARCHAR I believe I do not have this problem, but it is good to check. - It would be good for someone to test/confirm and post something to that effect (cc @Valdeirpsr).
REPLACE(CAST(orgsalkeyfil AS varchar(MAX)) ,'original', 'substituido')
– Bacco
Also evaluate the use of UPDATETEXT or STUFF()
– José Diz