/*-1.- Get the first letters of the Chinese character string
Based on strong posts. The two functions will be combined into a function. Can be applied to the inquiry of the help code - reproduced (earliest, the original author is unknown) - * / if EXISTS Select * from dbo.sysObjects where id = Object_id (n '[dbo]. [fgetpy]') and xtype in (n'fn ', n'if', n't ')) Drop function [dbo]. [fgetpy ] Go
- Creating Pinyin Functions Create Function FgetPy (@str varchar (500) = ') Returns Varchar (500) Asbegin Declare @strlen Int, @ Return Varchar (500), @ ii int declare @n int, @ c charr ( 1), @ chn nchar (1)
SELECT @ Strlen = LEN (@str), @ Return = '', @ ii = 0 set @ II = 0 while @ @ @Strlen Begin Select @ ii = @ ii 1, @ n = 63, @ chn = Substring (@ Str, @ II, 1) if @chn> 'Z' SELECT @n = @n 1, @ c = case chn by @Chn Ten char (@n) else @c End from (SELECT TOP 27 * FROM (Select chn = '' union all select '' union all select '咑' union all select '妸' union all select 'issued' union all select '旮' union all select '' union All select '丌' --Because Have no 'i' union all select '丌' union all select '咔' union all select '' union all select '呒' union all select 'taken' union all succ '' union All select '妑' union all select '' union all select '呥' union all select '仨' union all select 'he' union all select '屲' - NO 'u' union all succ '屲' --NO 'V' union all select '屲' Union All Select 'Xun' Union All Select '丫' Union All Select '帀' union all select @chn) as a order by chn collate Chinese _Prc_ci_as) AS B ELSE SET @ c = 'a' set @ Return = @ Return @ c end return (@return) endgo - Test Select DBO.FGETPY ('Dongguan') AS Dongguan City, dbo.fgetpy ('Ab) Central CHAVA ') AS Chinese
- Remove Pinyin Function DROP Function FGETPY
/*2.-- Function for the Pinyin for Chinese characters
Need to create a pinyin, including pronunciation of all Chinese characters, this can be obtained by converting a full-spelling input method, here only has a simple example. - * /
- Create Chinese Character Pinyae Create Table Yingshe (CHR Char (2), Py Varchar (10)) Insert Yingshe SELECT 'Long', 'Chang' Union All Select 'Long', 'ZHANG' Union All Select 'City', ' Cheng 'Union All SELECT', 'KEL' Union All SELECT ',' Ji 'Union All Select' Gold ',' Jin 'Union All SELECT', 'LI' Union All Select 'Chapter,' ZHANG 'Union All Select' 公 ',' Gong 'Union All Select' Divide ',' Si '/ * - The following is two functions, one of the tables returned to a string, one returned to a certain One of the pins of the string - * /
- Get the function of Chinese characters Pinyin - Return to all Pinyin Create Function F_GETPY_TB (@str varchar (100)) Returns @TB Table (RE VARCHAR (8000)) asbegindeclare @re table (ID INT, RE VARCHAR (8000)) - - Data processing intermediate table
Declare @i int, @ iln int @Str)
INSERT INTO @re selection @ i, py from yingshe where chr = substring (@ Str, @ i, 1) while @i <@ileenbegin set @ i = @ i 1 insert into @re select @ i, re @ splitchr Py from @re a, yingshe b where a.id=@i-1 and b.chr = Substring (@ Str, @ i, 1) end
INSERT INTO @TB Select RE from @re where id = @ itturn endgo
- Get the functions of Chinese characters Pinyin - Return to the Chinese characters for a pinyin Create Function F_Getpy (@str varchar (100)) Returns varchar (8000) asbegindeclare @re varchar (8000)
Declare @i int, @ iln int @Str)
Select @ re = py from yingshe where chr = substring (@ Str, @ i, 1) while @ @ ilenbegin set @ i = @ i 1 select top 1 @ re = @ RE @ splitchr py from yingshe where chr = Substring (@ Str, @ i, 1) endreturn (@RE) endGO
- Test - Return to 'Great Wall' All Pinyin Select * from dbo.f_getpy_tb ('Great Wall')
- Return the Pinyin of 'Great Wall' SELECT DBO.F_GETPY ('Great Wall')
- Remove the pinon function drop function f_getpy, f_getpy_tb