create function f_getpy
(@str nvarchar(4000))
returns nvarchar(4000)
as begin declare @strlen int,@re nvarchar(4000)
declare @t table(chr nchar(1) collate chinese_prc_ci_as,letter nchar(1))
insert into @t(chr,letter) select '吖 ', 'a ' union all select '八 ', 'b ' union all select '嚓 ', 'c '
union all select '咑 ', 'd ' union all select '妸 ', 'e ' union all select '發 ', 'f '
union all select '旮 ', 'g ' union all select '鉿 ', 'h ' union all select '丌 ', 'j '
union all select '咔 ', 'k ' union all select '垃 ', 'l ' union all select '嘸 ', 'm ' union all select '拏 ', 'n '
union all select '噢 ', 'o ' union all select '妑 ', 'p ' union all select '七 ', 'q ' union all select '呥 ', 'r '
union all select '仨 ', 's ' union all select '他 ', 't ' union all select '屲 ', 'w ' union all select '夕 ', 'x '
union all select '丫 ', 'y ' union all select '帀 ', 'z '
select @strlen=len(@str),@re= ' '
while @strlen> 0 begin select top 1 @re=letter+@re,@strlen=@strlen-1 from @t a
where chr <=substring(@str,@strlen,1)
order by chr desc if @@rowcount=0 select @re=substring(@str,@strlen,1)+@re,@strlen=@strlen-1 end return(@re)
end--樣例
if object_id('[pactinfo]') is not null
drop table [pactinfo]
go create table [pactinfo]([id] int,[pactname] varchar(4))
insert [pactinfo] select 1,'正常' union all select 2,'中國' union all select 3,'做飯'
union all select 4,'加發'
---查詢---
select * from [pactinfo] where left(dbo.f_getpy(pactname),1)='z'
select * from pactinfo where dbo.f_getpy(pactname) like '%z%'
--結果--- id pactname -----------
- 1 正常 2 中國 3 做飯 (所影響的行數為 3 行)
drop table [pactinfo]
drop function f_getpy
SQL中文轉拼音
使用下方的函式.忘了從哪抄的了.留存乙份 如果只要首字母.建議將資料 left tablefiled,1 後傳入函式 如果欄位是空或者null,不會報錯.返回空 方法體 set ansi nulls on goset quoted identifier on gocreate function db...
拼音字母進行SQL查詢指定欄位的實現
下文介紹的sql查詢方法是按照第乙個字是韻母進行查詢的,如果您對sql查詢方面感興趣的話,不妨一看,對您應該有所啟迪。如果要做乙個按拼音字母的sql查詢,應該怎麼做呢?下面就和大家分享拼音字母進行sql查詢指定欄位的實現方法,供您參考學習。比如說我們要查到指定字段第乙個字是以韻母 l 開頭的,我們可...
SQL獲取拼音首字函式
建立函式 create function f getpy str nvarchar 4000 returns nvarchar 4000 as begin declare strlen int,renvarchar 4000 declare ttable chr nchar 1 collate ch...