mssql sqlserver 獲取指定漢字的筆畫數的方法分享

Adeal2008發表於2018-08-02

轉自:http://www.maomao365.com/?p=6421

摘要:
下文講述計算漢字筆畫數的sql函式分享,如下所示:


例:建立漢字筆畫數sql函式 

create function [dbo].[fn_hanZiBiHuaShu](@char nchar(2)) 
returns int 
as 
begin 
return( 
case when unicode(@char) between 19968 and 40869 then( 
select top 1 id from( 
select id=1,ch=N`` 
union all select 2,N`` 
union all select 3,N`` 
union all select 4,N`` 
union all select 5,N`` 
union all select 6,N`` 
union all select 7,N`` 
union all select 8,N`` 
union all select 9,N`` 
union all select 10,N`` 
union all select 11,N`` 
union all select 12,N`` 
union all select 13,N`` 
union all select 14,N`` 
union all select 15,N`` 
union all select 16,N`` 
union all select 17,N`` 
union all select 18,N`` 
union all select 19,N`` 
union all select 20,N`` 
union all select 21,N`` 
union all select 22,N`` 
union all select 23,N`` 
union all select 24,N`` 
union all select 25,N`` 
union all select 26,N`` 
union all select 27,N`` 
union all select 28,N`` 
union all select 29,N`` 
union all select 30,N`` 
union all select 31,N`` 
union all select 32,N`` 
union all select 33,N`` 
union all select 35,N`` 
union all select 36,N`` 
union all select 39,N`` 
union all select 64,N`` 
)a where ch>=@char collate Chinese_PRC_Stroke_CS_AS_KS_WS 
order by id ASC) 
else 0 end) 
end

go

--測試獲取漢字筆畫數的sql函式 
select dbo.[fn_hanZiBiHuaShu](``)

drop function dbo.[fn_hanZiBiHuaShu]
go

 

相關文章