I would like to replace the text of a column in a table
I tried out:
select replace([article], '<p> </p>', '') from Articles
update Articles
set article = replace(article, '<p> </p>', '')
where article like '<p> </p>'
or
UPDATE [AJA].[dbo].[Articles]
SET [article] = ' '
WHERE [article] = '<p> </p>'
GO
and everytime it comes out with the error:
argument 1 not valid in replace
What's wrong with it?
Thanks for your help
I've check out your problem verifying with two datatype i.e.
ntext
: while working with ntext , it throws above error....Check out here
varchar(max)
: While working with varchar(max), it is perfectly workin....Check out here
So, use varchar(max)
datatype while working with html tag....
If you want to work on your previous type, then cast the column type as varchar
SELECT REPLACE(CAST([article] as VARCHAR(MAX)), '<p> </p>', '')
FROM Articles
You're getting this error because you've text datatype. With varchar datatype your query works fine.
You need to cast your field from text to varchar
in order to use replace function.
Declare @mytable table
(
Article text
);
INSERT into @mytable VALUES('<p> </p>');
INSERT into @mytable VALUES('<p> </p>');
INSERT into @mytable VALUES('<p> </p>');
INSERT into @mytable VALUES('<b> </b>');
select replace(cast([article] as VARCHAR(8000)),'<p> </p>','')
from @mytable
where Article LIKE '<p> </p>'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With