`
didasoft
  • 浏览: 154948 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

抄一个汉字转汉语拼音缩写的存储过程

阅读更多
If Exists (Select name From sysobjects
Where name = 'HZToPY' And type = 'FN')
Drop Function HZToPY
GO

Create Function HZToPY(@HZ VarChar(50))
Returns VarChar(50)
As
Begin
 Declare @PY VarChar(50),@LenHZ int,@i int,@FristWord VarChar(2)
 Set @LenHZ = Len(@HZ)
 Set @i = 1
 Set @PY = ''
 While @i <= @LenHZ
 Begin
   Set @FristWord = SubString(@HZ,@i,1)
 
   If( @FristWord < '八' )
   Begin
     If (@FristWord >= '0' And @FristWord <= '9') Set @PY = @PY + @FristWord
     Else If (@FristWord >= 'A' And @FristWord <= 'Z') Set @PY = @PY + @FristWord
     Else Set @PY = @PY + ''    
   End
   Else If( @FristWord < '嚓' ) Set @PY = @PY + 'B'
   Else If( @FristWord < '咑' ) Set @PY = @PY + 'C'
   Else If( @FristWord < '妸' ) Set @PY = @PY + 'D'
   Else If( @FristWord < '发' ) Set @PY = @PY + 'E'
   Else If( @FristWord < '旮' ) Set @PY = @PY + 'F'
   Else If( @FristWord < '铪' ) Set @PY = @PY + 'G'
   Else If( @FristWord < '讥' ) Set @PY = @PY + 'H'
   Else If( @FristWord < '咔' ) Set @PY = @PY + 'J'
   Else If( @FristWord < '垃' ) Set @PY = @PY + 'K'
   Else If( @FristWord < '嘸' ) Set @PY = @PY + 'L'
   Else If( @FristWord < '拏' ) Set @PY = @PY + 'M'
   Else If( @FristWord < '噢' ) Set @PY = @PY + 'N'
   Else If( @FristWord < '妑' ) Set @PY = @PY + 'O'
   Else If( @FristWord < '七' ) Set @PY = @PY + 'P'
   Else If( @FristWord < '亽' ) Set @PY = @PY + 'Q'
   Else If( @FristWord < '仨' ) Set @PY = @PY + 'R'
   Else If( @FristWord < '他' ) Set @PY = @PY + 'S'
   Else If( @FristWord < '哇' ) Set @PY = @PY + 'T'
   Else If( @FristWord < '夕' ) Set @PY = @PY + 'W'
   Else If( @FristWord < '丫' ) Set @PY = @PY + 'X'
   Else If( @FristWord < '帀' ) Set @PY = @PY + 'Y'
   Else If( @FristWord < '咗' ) Set @PY = @PY + 'Z'
   Else Set @PY = @PY + ''

   Set @i = @i + 1
 End
 Return (@PY)
End

Go
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics