Sql - replace argument with invalid

I would like to replace the text of a column in a table

I tried:

select replace([article], '<p>&nbsp;</p>', '') from Articles update Articles set article = replace(article, '<p>&nbsp;</p>', '') where article like '<p>&nbsp;</p>' or UPDATE [AJA].[dbo].[Articles] SET [article] = ' ' WHERE [article] = '<p>&nbsp;</p>' GO 

and every time it is issued with an error:

argument 1 is not valid when replacing

What is wrong with him?

thanks for the help

+4
source share
3 answers

I checked your problem with two data types i.e.

  • ntext : while working with ntext, it gives an error above ... Check here

  • varchar(max) : When working with varchar (max), this works fine ... Check here

So, use the varchar(max) data type when working with the html tag ....

If you want to work with your previous type, enter the column type as varchar

  SELECT REPLACE(CAST([article] as VARCHAR(MAX)), '<p>&nbsp;</p>', '') FROM Articles 
+6
source

You get this error because you have a text data type. With the varchar data type, your request works fine.

To use the replace function, you need to specify your field with text to varchar .

 Declare @mytable table ( Article text ); INSERT into @mytable VALUES('<p>&nbsp;</p>'); INSERT into @mytable VALUES('<p>&nbsp;</p>'); INSERT into @mytable VALUES('<p>&nbsp;</p>'); INSERT into @mytable VALUES('<b>&nbsp;</b>'); select replace(cast([article] as VARCHAR(8000)),'<p>&nbsp;</p>','') from @mytable where Article LIKE '<p>&nbsp;</p>' 
+3
source

Try this one

 UPDATE Articles SET article = REPLACE(article, '<p>&nbsp;</p>', '') 

Work on another is replaced in a similar way.

0
source

All Articles