提取汉字的首字母

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。



ALTER function [dbo].[udf_GetPYChar](@HZ varchar(50))
returns varchar(25)
as

begin

Declare @tmp binary(2)
Declare @Len int
Declare @PY varchar(25)
Declare @HZS varchar(2)
Declare @Index int

Set @Index = 1
Set @Len = Len(@HZ)
Set @PY = ''

While @Index<=@Len
Begin

Set @HZS = Substring(@HZ,@Index,1)

if @HZS='' or @HZS=''
begin
Set @Index = @Index+1
continue
end

Set @tmp = convert(binary(2),@HZS)


if (@tmp>=0xB0A1 and @tmp<=0xB0C4)
Set @PY = @PY + 'A'
else if (@tmp>=0xB0C5 and @tmp<=0xB2C0)
Set @PY = @PY + 'B'
else if (@tmp>=0xB2C1 and @tmp<=0xB4ED)
Set @PY = @PY + 'C'
else if (@tmp>=0xB4EE and @tmp<=0xB6E9)
Set @PY = @PY + 'D'
else if (@tmp>=0xB6EA and @tmp<=0xB7A1)
Set @PY = @PY + 'E'
else if (@tmp>=0xB7A2 and @tmp<=0xB8C0)
Set @PY = @PY + 'F'
else if (@tmp>=0xB8C1 and @tmp<=0xB9FD)
Set @PY = @PY + 'G'
else if (@tmp>=0xB9FE and @tmp<=0xBBF6)
Set @PY = @PY + 'H'
else if (@tmp>=0xBBF7 and @tmp<=0xBFA5)
Set @PY = @PY + 'J'
else if (@tmp>=0xBFA6 and @tmp<=0xC0AB)
Set @PY = @PY + 'K'
else if (@tmp>=0xC0AC and @tmp<=0xC2E7)
Set @PY = @PY + 'L'
else if (@tmp>=0xC2E8 and @tmp<=0xC4C2)
Set @PY = @PY + 'M'
else if (@tmp>=0xC4C3 and @tmp<=0xC5B5)
Set @PY = @PY + 'N'
else if (@tmp>=0xC5B6 and @tmp<=0xC5BD)
Set @PY = @PY + 'O'
else if (@tmp>=0xC5BE and @tmp<=0xC6D9)
Set @PY = @PY + 'P'
else if (@tmp>=0xC6DA and @tmp<=0xC8BA)
Set @PY = @PY + 'Q'
else if (@tmp>=0xC8BB and @tmp<=0xC8F5)
Set @PY = @PY + 'R'
else if (@tmp>=0xC8F6 and @tmp<=0xCBF9)
Set @PY = @PY + 'S'
else if (@tmp>=0xCBFA and @tmp<=0xCDD9)
Set @PY = @PY + 'T'
else if (@tmp>=0xCDDA and @tmp<=0xCEF3)
Set @PY = @PY + 'W'
else if (@tmp>=0xCEF4 and @tmp<=0xD188)
Set @PY = @PY + 'X'
else if (@tmp>=0xD1B9 and @tmp<=0xD4D0)
Set @PY = @PY + 'Y'
else if (@tmp>=0xD4D1 and @tmp<=0xD7F9)
Set @PY = @PY + 'Z'
else
Set @PY = @PY + UPPER(@HZS)

Set @Index = @Index+1

end /* while循环结束 */

return @PY
end




相关文档
最新文档