/****** 对象: UserDefinedFunction [dbo].[HZ2PY] 脚本日期: 05/02/2012 18:23:38 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
drop function getpy
go
--汉字转换拼音函数
create Function [dbo].[getpy]( @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 @vReturn
END
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
drop function getpy
go
--汉字转换拼音函数
create Function [dbo].[getpy]( @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 @vReturn
END