Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A rather quick domain specific solution may be to calculate a string similarity using SOUNDEX and a numeric distance between 2 strings. This will only really help when you have a lot of product codes.</p> <p>Using a simple UDF like below you can extract the numeric chars from a string so that you can then get 2200 out of 'CLC 2200npk' and 1100 out of 'CLC 1100' so you can now determine closeness based on the SOUNDEX output of each input as well as closeness of the numeric component of each input.</p> <pre><code>CREATE Function [dbo].[ExtractNumeric](@input VARCHAR(1000)) RETURNS INT AS BEGIN WHILE PATINDEX('%[^0-9]%', @input) &gt; 0 BEGIN SET @input = STUFF(@input, PATINDEX('%[^0-9]%', @input), 1, '') END IF @input = '' OR @input IS NULL SET @input = '0' RETURN CAST(@input AS INT) END GO </code></pre> <p>As far as general purpose algorithms go there are a couple which might help you with varying degrees of success depending on data set size and performance requirements. (both links have TSQL implementations available)</p> <ul> <li><a href="http://sqlmag.com/t-sql/double-metaphone-sounds-great">Double Metaphone</a> - This algo will give you a better match than soundex at the cost of speed it is really good for spelling correction though.</li> <li><a href="http://www.kodyaz.com/articles/fuzzy-string-matching-using-levenshtein-distance-sql-server.aspx">Levenshtein Distance</a> - This will calculate how many keypresses it would take to turn one string into another for instance to get from 'CLC 2200npk' to 'CLC 2200' is 3, while from 'CLC 2200npk' to 'CLC 1100' is 5.</li> </ul> <p><a href="http://randomrumenations.blogspot.de/2009/06/improved-t-sql-levenshtein-distance.html">Here</a> is an interesting article which applies both algos together which may give you a few ideas.</p> <p>Well hopefully some of that helps a little.</p> <p>EDIT: <a href="http://randomrumenations.blogspot.de/2009/06/improved-t-sql-levenshtein-distance.html">Here</a> is a much faster partial Levenshtein Distance implementation (read the post it wont return exact same results as the normal one). On my test table of 125000 rows it runs in 6 seconds compared to 60 seconds for the first one I linked to.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload