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
您需要使用'collate'子句和'cs'或'bin'排序規則。 – 2013-05-05 16:16:57
您好,Martin您好,請給我一個關於如何在我創建的示例函數中應用的示例? – user335160 2013-05-06 02:45:05
沒關係我明白了!謝謝 – user335160 2013-05-06 03:11:50