MSSQLSERVER 根據姓名儲存姓名的拼音字段

2021-08-30 07:09:43 字數 1734 閱讀 2571

1.申明乙個函式,用於名字到拼音的轉換

create function f_getpy(@str nvarchar(4000))

returns nvarchar(4000)

asbegin

declare @py table(

ch char(1),

hz1 nchar(1) collate chinese_prc_cs_as_ks_ws,

hz2 nchar(1) collate chinese_prc_cs_as_ks_ws)

insert @py select 'a',n'吖',n'鏊'

union  all select 'b',n'八',n'簿'

union  all select 'c',n'嚓',n'錯'

union  all select 'd',n'噠',n'跺'

union  all select 'e',n'屙',n'貳'

union  all select 'f',n'發',n'馥'

union  all select 'g',n'旮',n'過'

union  all select 'h',n'鉿',n'蠖'

union  all select 'j',n'丌',n'竣'

union  all select 'k',n'咔',n'廓'

union  all select 'l',n'垃',n'雒'

union  all select 'm',n'媽',n'穆'

union  all select 'n',n'拿',n'糯'

union  all select 'o',n'噢',n'漚'

union  all select 'p',n'趴',n'曝'

union  all select 'q',n'七',n'群'

union  all select 'r',n'蚺',n'箬'

union  all select 's',n'仨',n'鎖'

union  all select 't',n'他',n'籜'

union  all select 'w',n'哇',n'鋈'

union  all select 'x',n'夕',n'蕈'

union  all select 'y',n'丫',n'蘊'

union  all select 'z',n'匝',n'做'

declare @i int

set @i=patindex('%[吖-做]%' collate chinese_prc_cs_as_ks_ws,@str)

while @i>0

select @str=replace(@str,substring(@str,@i,1),ch)

,@i=patindex('%[吖-做]%' collate chinese_prc_cs_as_ks_ws,@str)

from @py

where substring(@str,@i,1) between hz1 and hz2

return(@str)

endgo

2.測試

select   dbo.f_getpy('風雲')   as   東莞市,dbo.f_getpy('ab中c國人')   as   中國人 

3.在資料庫中新加乙個pinyin欄位,然後通過函式進行更新

update person_main_test set pinyin=dbo.f_getpy(name)

根據姓名查詢學生的學號

完成日期 2013年12月10 版本號 v1.0 問題描述 根據姓名查詢學生的學號 樣例輸入 無 樣例輸出 無 問題分析 用簡單的方法,學會活學活用 include includeusing namespace std void jiaohuan int p1,int p2 string name ...

根據當前登入域賬號 獲取AD使用者姓名和所在OU目錄

region 根據當前登入域賬號 獲取ad使用者姓名和所在ou目錄 根據當前登入域賬號 獲取ad使用者姓名和所在ou目錄 返回域使用者是否存在 要搜尋的當前使用者名稱 out返回該使用者所在ou目錄 out 返回該使用者的姓名 搜尋域使用者是否存在 public static bool getadu...

MSSQLSERVER 儲存過程

系統儲存過程 列出sql server例項中的資料庫 sp databases 返回sql server 資料庫閘道器或基礎資料來源的特性名和匹配值的列表 sp server info 返回當前環境中的儲存過程列表 sp stored procedures 返回當前環境下可查詢的物件的列表 任何可出...