如何使用SQL Server将小字母字符替换为双字节

时间:2013-05-05 12:37:05

标签: sql-server-2008

如何仅在SQL Server中替换小字母字符?例如,如果我有一个文本A Simple Man。该文本应替换为A Söнрмï Mæо。我使用下面的脚本问题是大字母也被替换了。

ALTER FUNCTION [dbo].[sf_ReplaceCharacters] (@string NVARCHAR(MAX))
RETURNS NVARCHAR(MAX)
AS
BEGIN
    DECLARE @tmpString NVARCHAR(100)
    SET @tmpString = @string 
    set @tmpString=replace(@tmpString,N'a',N'æ')
    set @tmpString=replace(@tmpString,N'b',N'в')
    set @tmpString=replace(@tmpString,N'c',N'г')
    set @tmpString=replace(@tmpString,N'd',N'д')
    set @tmpString=replace(@tmpString,N'e',N'ï')
    set @tmpString=replace(@tmpString,N'f',N'ж')
    set @tmpString=replace(@tmpString,N'g',N'з')
    set @tmpString=replace(@tmpString,N'h',N'и')
    set @tmpString=replace(@tmpString,N'i',N'ö')
    set @tmpString=replace(@tmpString,N'j',N'к')
    set @tmpString=replace(@tmpString,N'k',N'л')
    set @tmpString=replace(@tmpString,N'l',N'м')
    set @tmpString=replace(@tmpString,N'm',N'н')
    set @tmpString=replace(@tmpString,N'n',N'о')
    set @tmpString=replace(@tmpString,N'o',N'Ą')
    set @tmpString=replace(@tmpString,N'p',N'р')
    set @tmpString=replace(@tmpString,N'q',N'с')
    set @tmpString=replace(@tmpString,N'r',N'т')
    set @tmpString=replace(@tmpString,N's',N'у')
    set @tmpString=replace(@tmpString,N't',N'ф')
    set @tmpString=replace(@tmpString,N'u',N'Č')
    set @tmpString=replace(@tmpString,N'v',N'ц')
    set @tmpString=replace(@tmpString,N'w',N'ч')
    set @tmpString=replace(@tmpString,N'x',N'ш')
    set @tmpString=replace(@tmpString,N'y',N'щ')
    set @tmpString=replace(@tmpString,N'z',N'ъ')
    RETURN @tmpString
END

1 个答案:

答案 0 :(得分:1)

正如马丁史密斯所说,我使用整理来使字符替换变得敏感。

SET @tmpString = @string 
set @tmpString=replace(@tmpString COLLATE Cyrillic_General_CS_AS,N'a',N'æ')