UPDATE error: "Argument data type text is invalid for argument 1 of REPLACE"

UPDATE error: "Argument data type text is invalid for argument 1 of REPLACE"

为什么我的查询会出现这个错误?

Msg 8116, Level 16, State 1, Line 3
Argument data type text is invalid for argument 1 of replace function.

查询:

UPDATE 
    tableName
SET
    fieldName = REPLACE (fieldName, '&lt;', '<')
WHERE
    id = 100

试试这个:

UPDATE tableName
SET fieldName = REPLACE (CONVERT(VARCHAR(MAX), fieldName), '&lt;', '<')
WHERE id = 100

这对你有用

UPDATE yourTableName
SET 
fieldName = REPLACE (CONVERT(VARCHAR(MAX), fieldName), '&lt;', '<')
WHERE id = 100

如果您想对大于 8000 个字符的文本进行相同的操作,您可以使用以下代码:

DECLARE @v VARCHAR(10) -- TEXT TO ADD
DECLARE @Vs VARHCAR(10) -- TEXT TO FIND
SET @v = 'String text to add'
SET @Vs = 'String text to find'


       UPDATE 
                yourTableName
        SET 
                textField = SUBSTRING(textField,1,DATALENGTH (textField)-LEN(@Vs)) + REPLACE( CAST(SUBSTRING(textField,DATALENGTH(textField)-LEN(@Vs)-1,DATALENGTH (textField)) AS VARCHAR(4)),@Vs,@v )
            WHERE 
                yourTableName.id = @iRifID -- Update for Table ID