sqlserver取字串拼音首字母

2022-07-22 04:27:15 字數 1967 閱讀 8009

sqlserver 使用函式獲取乙個字串的拼音首字母

create

function

dbo.fn_getpinyin

(

@str

nvarchar(max))

returns

nvarchar(max)as

begin

declare

@word

nchar(1),@py

nvarchar(max

)

set@py=''

while

len(@str)>

0begin

set@word

=left(@str,1

)

--如果非漢字字元,返回原字元

set@py

=@py

+(case

when

unicode(@word) between

19968

and19968

+20901

then (select

top1

py

from

(

select'a

'as py,n'驁'

asword

union

allselect'b

',n'簿'

union

allselect'c

',n'錯'

union

allselect'd

',n'鵽'

union

allselect'e

',n'樲'

union

allselect'f

',n'鰒'

union

allselect'g

',n'腂'

union

allselect'h

',n'夻'

union

allselect'j

',n'攈'

union

allselect'k

',n'穒'

union

allselect'l

',n'鱳'

union

allselect'm

',n'旀'

union

allselect'n

',n'桛'

union

allselect'o

',n'漚'

union

allselect'p

',n'曝'

union

allselect'q

',n'囕'

union

allselect'r

',n'鶸'

union

allselect's

',n'蜶'

union

allselect't

',n'籜'

union

allselect'w

',n'鶩'

union

allselect'x

',n'鑂'

union

allselect'y

',n'韻'

union

allselect'z

',n'咗'

) t

where word>=

@word

collate chinese_prc_cs_as_ks_ws

order

by py asc

)

else

@word

end)

set@str

=right(@str,len(@str)-1)

endreturn

@pyend

sqlserver 分段擷取字串

問題 最近在專案上碰到乙個關於清單排序的問題,系統根據清單編號進行排序,而資料庫儲存的清單編號是字串型別,當碰到清單編號為207 1,207 10,207 2這種情況時,頁面排序順序就為 207 1,207 10,207 2 正確的順序應該是 207 1,207 2,207 10。考慮到表中清單編號...

SQLServer擷取字串常用函式

sql server中一共提供了三個字串擷取函式 left right substring 函式說明如下 語法 left character,integer 引數介紹 引數1 要擷取的字串,引數2 擷取字元個數。返回值 返回從字串左邊開始指定個數的字元。示例sql select left sqlse...

C 取字串中間文字 取字串左邊 取字串右邊

好像是第二種效率高一點,取str字串中123左邊的所有字元 第一種between str,123 而第二種是between str,null,123 public static string between string str,string strleft,string strright 取文字中...