SQLServer 2008 创建获取中文字符串首字母
来源:互联网 发布:怎么样开农村淘宝网店 编辑:程序博客网 时间:2024/05/21 09:41
###创建获取中文首字母
#USE [bysd_changjiajinjie]
#GO
#
#/****** Object: UserDefinedFunction [dbo].[getPinYin] Script Date: 11/18/2013 23:19:08 ******/
#SET ANSI_NULLS ON
#GO
#
#SET QUOTED_IDENTIFIER ON
#GO
#
#CREATE FUNCTION [dbo].[getPinYin] (@str varchar(500) = '')
#RETURNS varchar(500) AS
#
#/*-------------------用于获取中文名称的首字母---------------------------------*/
#BEGIN
#Declare @strlen int,
#@return varchar(500),
#@ii int,
#@c char(1),
#@chn nchar(1)
#--//初始化变量
#Declare @pytable table(
#chn char(2) COLLATE Chinese_PRC_CS_AS NOT NULL,
#py char(1) COLLATE Chinese_PRC_CS_AS NULL,
#PRIMARY KEY (chn)
#)
#insert into @pytable values('吖', 'A')
#insert into @pytable values('八', 'B')
#insert into @pytable values('嚓', 'C')
#insert into @pytable values('咑', 'D')
#insert into @pytable values('妸', 'E')
#insert into @pytable values('发', 'F')
#insert into @pytable values('旮', 'G')
#insert into @pytable values('铪', 'H')
#--insert into @pytable values('丌', 'I')
#insert into @pytable values('丌', 'J')
#insert into @pytable values('咔', 'K')
#insert into @pytable values('垃', 'L')
#insert into @pytable values('嘸', 'M')
#insert into @pytable values('拏', 'N')
#insert into @pytable values('噢', 'O')
#insert into @pytable values('妑', 'P')
#insert into @pytable values('七', 'Q')
#insert into @pytable values('呥', 'R')
#insert into @pytable values('仨', 'S')
#insert into @pytable values('他', 'T')
#--insert into @pytable values('屲', 'U')
#--insert into @pytable values('屲', 'V')
#insert into @pytable values('屲', 'W')
#insert into @pytable values('夕', 'X')
#insert into @pytable values('丫', 'Y')
#insert into @pytable values('帀', 'Z')
#
#select @strlen = len(@str), @return = '', @ii = 0
#--//循环整个字符串,用拼音的首字母替换汉字
#while @ii < @strlen
#begin
#select @ii = @ii + 1, @chn = substring(@str, @ii, 1)
#if @chn > 'z' --//检索输入的字符串中有中文字符
#SELECT @c = max(py)
#FROM @pytable
#where chn <= @chn
#else
#set @c=@chn
#
#set @return=@return+@c
#end
#return @return
#END
#GO
#USE [bysd_changjiajinjie]
#GO
#
#/****** Object: UserDefinedFunction [dbo].[getPinYin] Script Date: 11/18/2013 23:19:08 ******/
#SET ANSI_NULLS ON
#GO
#
#SET QUOTED_IDENTIFIER ON
#GO
#
#CREATE FUNCTION [dbo].[getPinYin] (@str varchar(500) = '')
#RETURNS varchar(500) AS
#
#/*-------------------用于获取中文名称的首字母---------------------------------*/
#BEGIN
#Declare @strlen int,
#@return varchar(500),
#@ii int,
#@c char(1),
#@chn nchar(1)
#--//初始化变量
#Declare @pytable table(
#chn char(2) COLLATE Chinese_PRC_CS_AS NOT NULL,
#py char(1) COLLATE Chinese_PRC_CS_AS NULL,
#PRIMARY KEY (chn)
#)
#insert into @pytable values('吖', 'A')
#insert into @pytable values('八', 'B')
#insert into @pytable values('嚓', 'C')
#insert into @pytable values('咑', 'D')
#insert into @pytable values('妸', 'E')
#insert into @pytable values('发', 'F')
#insert into @pytable values('旮', 'G')
#insert into @pytable values('铪', 'H')
#--insert into @pytable values('丌', 'I')
#insert into @pytable values('丌', 'J')
#insert into @pytable values('咔', 'K')
#insert into @pytable values('垃', 'L')
#insert into @pytable values('嘸', 'M')
#insert into @pytable values('拏', 'N')
#insert into @pytable values('噢', 'O')
#insert into @pytable values('妑', 'P')
#insert into @pytable values('七', 'Q')
#insert into @pytable values('呥', 'R')
#insert into @pytable values('仨', 'S')
#insert into @pytable values('他', 'T')
#--insert into @pytable values('屲', 'U')
#--insert into @pytable values('屲', 'V')
#insert into @pytable values('屲', 'W')
#insert into @pytable values('夕', 'X')
#insert into @pytable values('丫', 'Y')
#insert into @pytable values('帀', 'Z')
#
#select @strlen = len(@str), @return = '', @ii = 0
#--//循环整个字符串,用拼音的首字母替换汉字
#while @ii < @strlen
#begin
#select @ii = @ii + 1, @chn = substring(@str, @ii, 1)
#if @chn > 'z' --//检索输入的字符串中有中文字符
#SELECT @c = max(py)
#FROM @pytable
#where chn <= @chn
#else
#set @c=@chn
#
#set @return=@return+@c
#end
#return @return
#END
#GO
- SQLServer 2008 创建获取中文字符串首字母
- 获取中文字符串拼音首字母
- 获取中文字符串的首字母
- php 获取中文字符串首字母
- ORACLE获取中文字符串拼音首字母
- js 获取中文字符串首字母 兼容英文字符串
- 获取中文首字母
- 获取中文拼音首字母
- 获取中文首字母
- C# 获取中文首字母
- asp获取中文首字母
- 获取中文字符串拼音首字母串的函数
- 【代码】php 中文字符串首字母函数的获取
- PHP获取字符串的第一个中文的首字母
- sqlserver 获取汉字拼音首字母
- 获取字符串首字母拼音
- 获取字符串首字母
- 字符串获取字符串的首字母
- 介绍一篇很不错的Objective-C的文章
- Hdu 1078 FatMouse and Cheese
- Mina框架【转】
- android中的Intent(意图)理解
- 课后习题Chapter1
- SQLServer 2008 创建获取中文字符串首字母
- 杭电1160
- git for ubuntu ----non-fast forward 解决办法
- uva 1344 Tian Ji The Horse Racing
- C++打开特定编码格式的文件(utf-8)
- MapReduce 编程模型在日志分析方面的应用
- 浅谈Linux用户权限管理之一(用户与组的概念)
- hdu oj 2022
- 黑马程序员--交通管理系统