1.创建数据表,
CREATE TABLE [dbo].[CodeConvert_GBBIG](
[GBField] [nchar](1) NULL,
[BigField] [nchar](1) NULL
) ON [PRIMARY]
2.从将excel数据插入到表CodeConvert_GBBIG
3.创建函数
CREATE FUNCTION [dbo].[Convert_GBBIG] (@str nvarchar(4000),@ToBIG bit) --@Str:要轉換的字符串.ToBIG 转换标志,为1,表示 GB-->BIG,否则是 BIG-->GB
RETURNS nvarchar(4000) AS
BEGIN
declare @returnStr varchar(4000),@index int,@repChar nchar(1),@indexChar nchar(1) --@Str字符串對應的每個字符
set @returnStr=''
set @index = 1
--循環取得轉換字符串的每個值
while @index <= Len(@str)
begin
set @repChar = '' --- 記得每次循環前要置@repChar為空
set @indexChar = SubString(@Str,@index,1)
/*------------------------得出取個字符對應的轉換字符---------------------------------*/
if @toBIG=1 --轉為繁體
select @repChar=IsNull(replace(@indexChar,GBField,BIGField) ,@indexChar)
from CodeConvert_GBBIG
where GBField = @indexChar
else --轉為簡體
select @repChar=IsNull(replace(@indexChar,BIGField,GBField),@indexChar)
from CodeConvert_GBBIG
where BIGField = @indexChar
/*--------------------------- 取字符結束 ------------------------------------------*/
set @index = @index+1
if @repChar=''
set @returnStr = @returnStr + @indexChar
else
set @returnStr = @returnStr + @repChar
end
return (@returnStr)
END
4.执行查询
--建立繁簡轉換函數:
select dbo.Convert_GBBIG('建立繁簡轉換函數',0)
select dbo.Convert_GBBIG('建立繁简转换函数',1)
简繁数据库execl数据下载链接