sqlserver 快速生成汉字的首拼字母的函数(经典)

前端之家收集整理的这篇文章主要介绍了sqlserver 快速生成汉字的首拼字母的函数(经典)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

代码如下: @H_502_0@<div class="codetitle"><a style="CURSOR: pointer" data="43763" class="copybut" id="copybut43763" onclick="doCopy('code43763')"> 代码如下:

<div class="codebody" id="code43763"> @H_5020@USE [tempdb] @H5020@GO @H502_0@/** Object: UserDefinedFunction [dbo].[fungetPY] Script Date: 05/23/2012 18:03:45 **/ @H502_0@SET ANSINULLS ON @H5020@GO @H502_0@SET QUOTEDIDENTIFIER ON @H5020@GO @H5020@/* @H502_0@获取汉字的首拼音 @H_5020@如果是非汉字字符 @H5020@*/ @H502_0@ALTER function [dbo].[fungetPY] @H5020@( @H5020@@str nvarchar(4000) @H5020@) @H5020@returns nvarchar(4000) @H5020@as @H5020@begin @H5020@declare @word nchar(1),@PY nvarchar(4000) @H5020@set @PY='' @H5020@while len(@str)>0 @H5020@begin @H5020@set @word=left(@str,1) @H5020@--如果非汉字字符,返回原字符 @H5020@set @PY=@PY+(case when unicode(@word) between 19968 and 19968+20901 @H5020@then ( @H5020@select top 1 PY @H5020@from @H5020@( @H5020@select 'A' as PY,N'驁' as word @H5020@union all select 'B',N'簿' @H5020@union all select 'C',N'錯' @H5020@union all select 'D',N'鵽' @H5020@union all select 'E',N'樲' @H5020@union all select 'F',N'鰒' @H5020@union all select 'G',N'腂' @H5020@union all select 'H',N'夻' @H5020@union all select 'J',N'攈' @H5020@union all select 'K',N'穒' @H5020@union all select 'L',N'鱳' @H5020@union all select 'M',N'旀' @H5020@union all select 'N',N'桛' @H5020@union all select 'O',N'漚' @H5020@union all select 'P',N'曝' @H5020@union all select 'Q',N'囕' @H5020@union all select 'R',N'鶸' @H5020@union all select 'S',N'蜶' @H5020@union all select 'T',N'籜' @H5020@union all select 'W',N'鶩' @H5020@union all select 'X',N'鑂' @H5020@union all select 'Y',N'韻' @H5020@union all select 'Z',N'咗' @H5020@) T @H502_0@where word>=@word collate Chinese_PRC_CS_AS_KSWS @H5020@order by PY ASC @H5020@) @H5020@else @word @H5020@end) @H5020@set @str=right(@str,len(@str)-1) @H5020@end @H5020@return upper(@PY) @H5020@end @H5020@
@H502_0@调用如下: @H_502_0@<div class="codetitle"><a style="CURSOR: pointer" data="35477" class="copybut" id="copybut35477" onclick="doCopy('code35477')"> 代码如下:
<div class="codebody" id="code35477"> @H_502_0@select dbo.fun_getPY 首拼 @H_5020@
@H5020@结果: @H502_0@ZGR

原文链接:https://www.f2er.com/mssql/63824.html

猜你在找的MsSQL相关文章