小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

求第一個(gè)字符串中第二個(gè)串的個(gè)數(shù),綜合模糊查詢(xún)

 zww_blog 2012-03-15
求第一個(gè)字符串中第二個(gè)串的個(gè)數(shù)
分類(lèi): SQL函數(shù)分享系列


--創(chuàng)建函數(shù)

create function [dbo].[m_count]

(

    @str_one nvarchar(200),  --第一個(gè)字符串

    @str_two nvarchar(200)   --第二個(gè)字符串

)

returns int as

begin

    declare @sqlcount int

    select @sqlcount=(len(@str_one)-len(replace(@str_one,@str_two,'')))/len(@str_two)

return @sqlcount

end

 

--測(cè)試示例

select dbo.m_count('sqlserver','e') as [count]

 

--運(yùn)行結(jié)果

/*

count

-----------

2

*/


綜合模糊查詢(xún)


--創(chuàng)建函數(shù)

create function [dbo].[m_fuzzyquery_v1]

(

    @str nvarchar(2000)

)  

returns nvarchar(2000)

as  

begin  

       declare @count int,@i int;

       declare @newchar nvarchar(200),@nn nvarchar(300),@hh nvarchar(200)

       set @count=len(@str);set @i=1;set @nn='';

       while @i<@count+1

       begin

           set @newchar=substring(@str,@i,1)+'%'

           set @nn=@nn+@newchar;

           set @i=@i+1;

       end

    set @hh='%'+@nn

    return @hh

end

 

--測(cè)試數(shù)據(jù)

declare @table table (connect varchar(30))

insert into @table

select '我愛(ài)程序' union all

select '我的程序生活' union all

select '絕對(duì)無(wú)聊的生活' union all

select '活得好累' union all

select '程序員的生活' union all

select '序論' union all

select '生機(jī)' union all

select '生活雜志' union all

select '我只是隨便寫(xiě)寫(xiě)' union all

select '真的是要來(lái)搜索的' union all

select '程序員一生的活路'

 

--普通的模糊查詢(xún)

select * from @table where connect like '%程序生活%'

--運(yùn)行結(jié)果

/*

connect

------------------------------

我的程序生活

*/

 

--應(yīng)用函數(shù)查詢(xún)

select * from @table where connect like ( select dbo.[m_fuzzyquery_v1]('程序生活'))

--運(yùn)行結(jié)果

/*

connect

------------------------------

我的程序生活

程序員的生活

程序員一生的活路

*/

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶(hù)發(fā)布,不代表本站觀(guān)點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買(mǎi)等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶(hù) 評(píng)論公約

    類(lèi)似文章 更多