我有一个基本上从选择中去除数字的功能。此功能适用于基于英语的字符集。我有一组由非英文字符(中文、日文、印度文等)组成的新数据,但我没有得到预期的效果。我正在使用该NVarchar
集合来存储任何可能是非英语的记录。以下是我目前正在使用的功能。任何建议都会非常有帮助。
GO
/****** Object: UserDefinedFunction [dbo].[StripVenName] Script Date: 05/03/2012 16:24:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE FUNCTION [dbo].[StripVenName] (@InString as VarChar(8000))
RETURNS NVarChar(100) AS
BEGIN
Declare @ReturnVal as NVarchar(4000)
Declare @OutString as NVarchar(4000)
Declare @Pos as smallint
Declare @CurChar as NVarChar(1)
IF LEN(@InString) = 0
SET @ReturnVal = ''
ELSE
BEGIN
Set @Pos = 1
SET @OutString = ' '
WHILE (@Pos <= Len(@InString))
BEGIN
Set @CurChar = SUBSTRING(@InString, @Pos, 1)
if ASCII(@CurChar) between 65 and 90 or ASCII(@CurChar) between 97 and 122
SET @OutString = @OutString + @CurChar
Set @Pos = @Pos + 1
END
if len(@OutString) = 0
SET @OutString = @InString
SET @ReturnVal = LTRIM(RTRIM(@OutString))
END
RETURN @ReturnVal
END