请问如何,在SQL中取中文字符中第一个字的首字母

[复制链接]
查看11 | 回复2 | 2013-1-17 12:18:56 | 显示全部楼层 |阅读模式
如中国,取z
北京,取b

还向各位大虾请教
回复

使用道具 举报

千问 | 2013-1-17 12:18:56 | 显示全部楼层
這個問題不好搞
回复

使用道具 举报

千问 | 2013-1-17 12:18:56 | 显示全部楼层

--可支持大字符集20000个汉字!
create function f_ch2py(@chn nchar(1))
returns char(1)
as
begin
declare @n int
declare @c char(1)
set @n = 63
select @n = @n +1,
@c = case chn when @chn then char(@n) else @c end
from(
select top 27 * from (
select chn =
'吖' union all select
'八' union all select
'嚓' union all select
'咑' union all select
'妸' union all select
'发' union all select
'旮' union all select
'铪' union all select
'丌' union all select--because have no 'i'
'丌' union all select
'咔' union all select
'垃' union all select
'嘸' union all select
'拏' union all select
'噢' union all select
'妑' union all select
'七' union all select
'呥' union all select
'仨' union all select
'他' union all select
'屲' union all select--no 'u'
'屲' union all select--no 'v'
'屲' union all select
'夕' union all select
'丫' union all select
'帀' union all select @chn) as a
order by chn COLLATE Chinese_PRC_CI_AS
) as b
return(@c)
end
go
select dbo.f_ch2py('中')--Z
select dbo.f_ch2py('国')--G
select dbo.f_ch2py('人')--R
select dbo.f_ch2py('镆')--M
go
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行