将字符串中的字母、数字字符过滤掉create function f_1(@a nvarchar(4000))
returns nvarchar(4000)
begin
  declare @b nvarchar(4000)
  set @b=''
  while @a<>''
  begin
    select @b=@b+left(@a,1)
      where unicode(left(@a,1)) between 48 and 57
         or unicode(left(@a,1)) between 65 and 90
         or unicode(left(@a,1)) between 97 and 122
    set @a=right(@a,len(@a)-1)
  end
  return(@b)
end
go
--调用
select dbo.f_1(col) from t

解决方案 »

  1.   

    有个方法倒可以考虑一下,汉字的编码超过ASCII值。
      

  2.   

    declare @a varchar(1000)
    declare @b varchar(1000)
    set @a='jlkj汉字134234'
    set @b=''
    while len(@a)>0
    begin
    if unicode(left(@a,1))<=19968
    begin
    set @a=stuff(@a,1,1,'')
    end
    else 
    begin
    set @b=@b+left(@a,1)
    set @a=stuff(@a,1,1,'')
    end
    end
    print @b
      

  3.   

    改一下:if unicode(left(@a,1))<=19968  --改为<19968如果你只是去掉数字,把上面的条件改为:if unicode(left(@a,1))<=57 and unicode(left(@a,1))>=48