SQL汉字转拼音

 1 create   Function [dbo].[HZToPY](@HZ VarChar(255))
 2 Returns VarChar(255)
 3 As
 4 Begin 
 5  Declare @PY VarChar(255),@LenHZ int,@i int,@FristWord VarChar(2)
 6  Set @LenHZ = Len(@HZ)
 7  Set @i = 1
 8  Set @PY = ''
 9  While @i <= @LenHZ
10  Begin 
11    Set @FristWord = SubString(@HZ,@i,1)
12    If( @FristWord < '' )
13    Begin
14      If (@FristWord >= '0' And @FristWord <= '9') Set @PY = @PY + @FristWord
15      Else If (@FristWord >= 'A' And @FristWord <= 'Z') Set @PY = @PY + @FristWord
16      Else If (@FristWord = '+' ) Set @PY = @PY + '+'
17      Else If (@FristWord = '-' ) Set @PY = @PY + '-'
18      Else If (@FristWord = '<' ) Set @PY = @PY + '<'
19      Else If (@FristWord = '>' ) Set @PY = @PY + '>'
20      Else If (@FristWord = '-' ) Set @PY = @PY + '-'
21      Else if( @FristWord >= '!' And @FristWord <='~') Set @PY = @PY + @FristWord
22      Else if (ASCII(@FristWord) = 176) set @PY = @PY + 'A'
23      Else Set @PY = @PY + @FristWord    
24    End 
25    --Else If( @FristWord < '吖' ) Set @PY = @PY + 'A' 
26    Else If( @FristWord < '' ) Set @PY = @PY + 'B' 
27    Else If( @FristWord < '' ) Set @PY = @PY + 'C'
28    Else If( @FristWord < '' ) Set @PY = @PY + 'D'
29    Else If( @FristWord < '' ) Set @PY = @PY + 'E'
30    Else If( @FristWord < '' ) Set @PY = @PY + 'F'
31    Else If( @FristWord < '' ) Set @PY = @PY + 'G' 
32    Else If( @FristWord < '' ) Set @PY = @PY + 'H' 
33    Else If( @FristWord < '' ) Set @PY = @PY + 'J' 
34    Else If( @FristWord < '' ) Set @PY = @PY + 'K' 
35    Else If( @FristWord < '' ) Set @PY = @PY + 'L' 
36    Else If( @FristWord < '' ) Set @PY = @PY + 'M' 
37    Else If( @FristWord < '' ) Set @PY = @PY + 'N' 
38    Else If( @FristWord < '' ) Set @PY = @PY + 'O' 
39    Else If( @FristWord < '' ) Set @PY = @PY + 'P' 
40    Else If( @FristWord < '' ) Set @PY = @PY + 'Q' 
41    Else If( @FristWord < '' ) Set @PY = @PY + 'R' 
42    Else If( @FristWord < '' ) Set @PY = @PY + 'S' 
43    Else If( @FristWord < '' ) Set @PY = @PY + 'T' 
44    Else If( @FristWord < '' ) Set @PY = @PY + 'W' 
45    Else If( @FristWord < '' ) Set @PY = @PY + 'X' 
46    Else If( @FristWord < '' ) Set @PY = @PY + 'Y' 
47    Else If( @FristWord < '' ) Set @PY = @PY + 'Z' 
48    Else Set @PY = @PY + ''
49 
50    Set @i = @i + 1
51  End
52  Return (upper(@PY))
53 End
原文地址:https://www.cnblogs.com/jieke/p/3013590.html