重音字母及其基字母的ascci值相同

时间:2019-02-21 06:06:11

标签: sql sql-server ascii diacritics accent-sensitive

我正在使用ascii转换从字符串中除去a-z,A-Z和0-9以外的所有字母/字符。但是当我尝试同样的方法时,我会收到带有重音符号的字母。虽然将CustomerName与'āb'转换为'ab',但我的预期结果只是'b'。根据我的理解,重音值的取值为ascii值与其基数相同。如果您有任何想法请帮助。附加我的代码

CREATE FUNCTION dbo.RemoveSpecialChar (@s VARCHAR(256)) 
RETURNS VARCHAR(256)
WITH SCHEMABINDING
    BEGIN
        IF @s IS NULL
            RETURN NULL
        DECLARE @s2 VARCHAR(256) = '',
                @l INT = LEN(@s),
                @p INT = 1

        WHILE @p <= @l
            BEGIN
                DECLARE @c INT
                SET @c = ASCII(SUBSTRING(@s, @p, 1))
                IF @c BETWEEN 48 AND 57
                   OR  @c BETWEEN 65 AND 90
                   OR  @c BETWEEN 97 AND 122
                    SET @s2 = @s2 + CHAR(@c)
                SET @p = @p + 1
            END

        IF LEN(@s2) = 0
            RETURN NULL

        RETURN @s2
        end

SELECT  [dbo].[RemoveSpecialChar](CAST(Name AS nvarchar(255))) as CustomerName
from  Customers

0 个答案:

没有答案