/****** 对象: UserDefinedFunction [dbo].[HZ2PY] 脚本日期: 05/02/2012 18:23:38 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGO--汉字转换拼音函数ALTER Function [dbo].[HZ2PY]( @cString nVarChar (200)) Returns nVarChar(100)AS Begin Declare @nFor Int --字符串循环用 Declare @nPYFor Int --拼音串循环用 Declare @cPYString VarChar(100) --拼音串 Declare @cCurChar VarChar(2) --当前字符 Declare @vReturn VarChar (100) ----将返回的结果 Set @cPYString = '吖八嚓咑妸发旮铪讥讥咔垃呣拿讴趴七呥仨他哇哇哇夕丫匝咗' Set @vReturn = '' Set @nFor = 0 While @nFor < Len(@cString) Begin Set @nFor = @nFor + 1 Set @cCurChar = Substring(@cString,@nFor,1) Set @nPYFor = 0 While @nPYFor < len(@cPYString) Begin Set @nPYFor = @nPYFor + 1 If @cCurChar < Substring(@cPYString,@nPYFor,1) Begin Set @vReturn = Rtrim(@vReturn) + (Case When @nPYFor <> 1 Then Char(63 + @nPYFor) Else @cCurChar End) Break End Else Begin Continue End End End Return @vReturnEND