SQL函数取汉字拼音首字母

 1 CREATE function f_GetFirstPy(@str varchar(50)='')
 2     returns char(1)
 3 as
 4 begin
 5     declare @n int, @c char(1), @chn nchar(1)
 6     select @n=63, @chn=substring(@str,1,1)
 7     if @chn > 'z'
 8         if( @chn < '' ) set @c = 'A'
 9         else if ( @chn < '' ) set @c = 'B'
10         else if ( @chn < '' ) set @c = 'C'
11         else if ( @chn < '' ) set @c = 'D'
12         else if ( @chn < '' ) set @c = 'E'
13         else if ( @chn < '' ) set @c = 'F'
14         else if ( @chn < '' ) set @c = 'G'
15         else if ( @chn < '' ) set @c = 'H'
16         else if ( @chn < '' ) set @c = 'I'
17         else if ( @chn < '' ) set @c = 'J'
18         else if ( @chn < '' ) set @c = 'K'
19         else if ( @chn < '' ) set @c = 'L'
20         else if ( @chn < '' ) set @c = 'M'
21         else if ( @chn < '' ) set @c = 'N'
22         else if ( @chn < '' ) set @c = 'O'
23         else if ( @chn < '' ) set @c = 'P'
24         else if ( @chn < '' ) set @c = 'Q'
25         else if ( @chn < '' ) set @c = 'R'
26         else if ( @chn < '' ) set @c = 'S'
27         else if ( @chn < '' ) set @c = 'T'
28         else if ( @chn < '' ) set @c = 'U'
29         else if ( @chn < '' ) set @c = 'V'
30         else if ( @chn < '' ) set @c = 'W'
31         else if ( @chn < '' ) set @c = 'X'
32         else if ( @chn < '' ) set @c = 'Y'
33         else set @c = 'Z'
34     else if @chn <= 'z' and @chn >= 'a'
35         set @c = upper(@chn)
36     else if @chn <= 'Z' and @chn >= 'A'
37         set @c = @chn
38     else
39         set @c = ''
40     return (@c)
41 end

 

转载于:https://www.cnblogs.com/xuejietong/p/8902166.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值