假设你的字符串为@s
while patindex('%[^'^0-9,^a-z,^A-Z,^ ]%',@s)>0 
   stuff(@s,patindex('%[^'^0-9,^a-z,^A-Z,^ ]%',@s),1,'')

解决方案 »

  1.   

    create function f_replace(@str varchar(8000))
    returns varchar(8000)
    as
    begin
          while patindex('%[^a-zA-Z^0-9^ ^'']%',@str)>0
          begin
                set @str=stuff(@str,patindex('%[^a-zA-Z^0-9^ ^'']%',@str),1,'')
          end      return @str
    end
    go--调用
    select dbo.f_replace('2dg6<;L,')/*
    2dg6L(所影响的行数为 1 行)
    */
      

  2.   

    运行以后,发现还是有末尾ASCII码为63的去除不了,怎么回事?
      

  3.   

    create function f_replace(@str varchar(8000))
    returns varchar(8000)
    as
    begin
          while patindex('%[^a-zA-Z^0-9^ ^'']%',@str)>0
          begin
                set @str=stuff(@str,patindex('%[^a-zA-Z^0-9^ ^'']%',@str),1,'')
          end      return @str
    end
    go--调用
    select dbo.f_replace('2dg6<;L,?')/*
    2dg6L(所影响的行数为 1 行)
    */
      

  4.   


    declare @s varchar(8000),@s1 varchar(8000)
    set @s='  0(az*Jah.adf8UU'while patindex('%[^''^0-9,^a-z,^A-Z,^ ]%',@s)>0 
     set @s=stuff(@s,patindex('%[^''^0-9,^a-z,^A-Z,^ ]%',@s),1,'')select @s