/*此函数用于去除字符串中非允许存在的字符,允许的字符集可以用AllowLetter定义*/<br>/*中文汉字在字符串里还是保留的*/<br>CREATE FUNCTION LetterOnly ( @oldStr nvarchar(500) ) <br>RETURNS nvarchar(500) AS <br>BEGIN <br>declare @AllowLetter varchar(50), @NotAllowLetter varchar(500), @Returns nvarchar(500)<br>declare @i integer<br>select @AllowLetter='ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'<br>select @NotAllowLetter=' ̄!@#¥%^&*()_-+=|、{}《》[]:;<>,。、?“”‘‘’ '<br>select @i=1<br>select @OldStr=upper(@OldStr)<br>select @Returns=''<br>while @i <= len(@OldStr)<br> begin<br> if (ascii(substring(@OldStr, @i, 1)) >= 128 ) and (charindex( substring( @OldStr, @i, 1), @NotAllowLetter ) =0) <br> select @Returns=@Returns+ substring( @OldStr, @i, 1)<br> else<br> if charindex( substring( @OldStr, @i, 1), @AllowLetter ) >0<br> select @Returns=@Returns+ substring( @OldStr, @i, 1)<br> select @i=@i+1<br> end<br>return @Returns<br><br>END<br><br><br>参考这个函数,自己再做就不难了。