惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
V2EX
博客园 - 叶小钗
WordPress大学
WordPress大学
N
Netflix TechBlog - Medium
M
MIT News - Artificial intelligence
美团技术团队
aimingoo的专栏
aimingoo的专栏
博客园_首页
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Microsoft Security Blog
Microsoft Security Blog
Last Week in AI
Last Week in AI
The GitHub Blog
The GitHub Blog
小众软件
小众软件
T
Tailwind CSS Blog
Martin Fowler
Martin Fowler
B
Blog RSS Feed
月光博客
月光博客
量子位
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Hugging Face - Blog
Hugging Face - Blog
IT之家
IT之家
Y
Y Combinator Blog
B
Blog
MyScale Blog
MyScale Blog

博客园 - PC167

caiquan0 sheeeeee loggggg ato ctrl const loginnnnn pauto Shenmi llllll controller ctypes helper python test 1 Index was outside the bounds of the array. (Microsoft.SqlServer.Smo) contains 方法 mysql connector 和 sqlserver ado.net 的区别 javascript slice javascript bind 转,SelectNodes + XPath jsgen 搭建 【转】基于第一个PhoneGap(cordova)的应用详解 回车和换行 html中空格转义字符 输出乘法表 sql server 2008 r2 报错 razor 拼接字符串 转,CV和resume的区别 b/s开发者的困境 sql 下,float和numeric
sql server 相似度对比
PC167 · 2014-08-29 · via 博客园 - PC167

转自:http://www.dotblogs.com.tw/rachen/archive/2008/10/07/5611.aspx

函數一.產生 Like 比對用字串

create function fn_get_fuzzy_str( @instr nvarchar(256) )
returns nvarchar(513)
as begin
    /*依據傳入字串補上%符號*/
    /*
    declare @instr nvarchar(256);
    set @instr = N'樹林國民小學'; */

    declare @outstr nvarchar(513)
    
    if isnull(@instr,'') = '' begin
  set @outstr = '';
    end else begin
  declare @i int;
  set @i = 1;    
  set @outstr = '%';
  while @i <= len(@instr) begin
      set @outstr = @outstr + substring(@instr,@i,1) + '%';
      set @i = @i + 1;
  end
    end
    return @outstr;
end

函數二.查詢函數

create function fn_str_fuzzy_qry( @src_str nvarchar(256) , @match_str nvarchar(256) , @setp int  )
returns int
as begin
    /*字串相似度比對 結果直越大相似度越高*/
    /*
    declare @src_str nvarchar(256); --比對來源
    declare @match_str nvarchar(256); --比對字串
    declare @setp int;    --每次步減幾個字
    */
    declare @fuzzy_str nvarchar(513);
    declare @like_str  nvarchar(513);

    set @fuzzy_str = dbo.fn_get_fuzzy_str(@match_str);

    return case
  when @src_str like @fuzzy_str then
      4000 + 1000 - len(@src_str)
  when ( len(@fuzzy_str) - @setp*2*1 >= 5 ) and @src_str like left(@fuzzy_str,len(@fuzzy_str) - @setp*2*1) then
      3000 + 1000 - len(@src_str)
  when ( len(@fuzzy_str) - @setp*2*2 >= 5 ) and @src_str like left(@fuzzy_str,len(@fuzzy_str) - @setp*2*2) then
      2000 + 1000 - len(@src_str)
  when ( len(@fuzzy_str) - @setp*2*3 >= 5 ) and @src_str like left(@fuzzy_str,len(@fuzzy_str) - @setp*2*3) then
      1000 + 1000 - len(@src_str)
  else 0
    end

end

應用方式

select school_name , ......
from bas_info
where
    dbo.fn_str_fuzzy_qry(school_name,N'樹林國小',1) > 0
order by dbo.fn_str_fuzzy_qry(school_name,N'樹林國小',1) desc