简体   繁体   English

模式匹配SQL算法

[英]Pattern matching sql algorithm

Table 1
Account ID   Account name 
Missing      Agreete NV.


Table 2 
Account ID   Account name 
XXX4546778   Agreete

I have to pouplate all the Account IDs in Table 1 based on the best match looking at the account name in both tables . 我必须根据两个表中的帐户名的最佳匹配来对表1中的所有帐户ID进行组合。

I thought about like, patindex & soundex. 我想到了patindex和soundex。

Thinking about it I was thinking compare full string, if no match then compare full string -1 , if not match then then compare full string -2 until you get a match. 考虑一下,我在想比较完整字符串,如果不匹配则比较完整字符串-1,如果不匹配则比较完整字符串-2直到获得匹配。

However someone must have came up with Pattern matching sql algorithm that will do this with a low error rate . 但是,一定有人想出了模式匹配sql算法,它将以较低的错误率执行此操作。 Any ideas ? 有任何想法吗 ?

Perhaps im missing the point of your question but it seems to me you have the exact match like you said 也许我错过了您的问题的要点,但在我看来,您与您所说的完全匹配

update t1
set [account id] = t2.[account id]
from table1 t1
inner join table2 t2 on t1.[account name] = t2.[account name]
where t1.[account id] = 'missing'

And you have the partial match 你有部分比赛

update t1
set [account id] = t2.[account id]
from table1 t1
inner join table2 t2 on t1.[account name] like t2.[account name] + '%'
where t1.[account id] = 'missing'

run in that order... 按顺序运行...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM