2013-05-05 66 views
1

如何僅替換SQL Server中的小型字母字符?例如,如果我有一個文本A Simple Man。文本應該替換爲A Söнрмï Mæо。我使用腳本下面的問題是大信也被取代了。如何使用SQL Server將小型字母字符替換爲雙字節

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 
+0

您需要使用'collat​​e'子句和'cs'或'bin'排序規則。 – 2013-05-05 16:16:57

+0

您好,Martin您好,請給我一個關於如何在我創建的示例函數中應用的示例? – user335160 2013-05-06 02:45:05

+0

沒關係我明白了!謝謝 – user335160 2013-05-06 03:11:50

回答

1

正如馬丁史密斯提到的那樣,我使用整理來使字符替換敏感。

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

謝謝你發佈你的答案。 – 2013-05-07 12:44:12

相關問題