在查询器里执行以下这句SQL语句,出错了,提示:函数 replace 的参数 1 的数据类型 ntext 无效。
english_details是ntext类型的,如果我要将english_details里含有"<p>"的字符替换成空的字符,要怎么修改.
谢谢.
UPDATE product SET english_details=REPLACE(english_details,'''+<p>+''','''')

解决方案 »

  1.   

    --创建测试环境
    create table product (id int identity,english_details ntext)
    insert into product select 'abc<p>axe<p>,asd'
    union all select  'a01t<p>ce4<p>56d'--定义替换的字符串
    declare @s_str varchar(8000),@d_str varchar(8000)
    select @s_str='<p>' --要替换的字符串
    ,@d_str=''          --替换成的字符串--字符串替换处理
    declare @p varbinary(16),@postion int,@rplen int,@i int
    set @i = 1
    while @i <= (select count(*) from product)
    begin
     select @p=textptr(english_details),@rplen=len(@s_str),@postion=charindex(@s_str,english_details)-1 from product
     where id = @i 
    while @postion>0
    begin
    updatetext product.english_details @p @postion @rplen @d_str
    select @postion=charindex(@s_str,english_details)-1 from product where id = @i 
    end
     set @i = @i + 1
    end--显示结果
    select * from productid     english_details
    ---------------------------
    1 abcaxe,asd
    2 a01tce456d
      

  2.   

     UPDATE product SET english_details=REPLACE(english_details,'<p>','')
      

  3.   


    UPDATE product SET english_details=REPLACE(english_details,' <p>','')
      

  4.   

    UPDATE product SET english_details=REPLACE(english_details,' <p>','')
    谢谢各位了.特别是ydage 
    我是这样写的:
    UPDATE product set china_details=replace(cast(china_details as varchar(8000)) ,'<p>','  ')用cast来转换一下.