sql server - SQL: Can I use CHARINDEX to return the best match not just the first match? -
Not sure if this bela will work I want to return to code 2 by joining CHARINDEX.
As another example, I have a description table (DT) that looks like this:
ID details code 158 99 159 Interested in Interest 383 160 Account Due to 384 Interest Due
and a Master Table (MT) with such entries:
ID Anger code 1 interest I need to set the code on the master table to 383. When I do INSERT based on a join using Chirindax (DT.Description, MT Discription)> 0, it sets mt.code at 199 each time. How do I drag the host table from the description table with the best match, not just the first matching example? Thank you!
You can use a simple addition to simply find a match with A. Longest time Leave up to finish all of the match; update t1 SET t1.codeA = t2_1.codeB from table 1 t1 JOIN table2 t2_1 at CHARINDEX (t2_1 .colb, t1.colA)> ; On CharacterX (T2_2.colB, t1.colA) & gt; 0 and T2_1.codeB & lt; & Gt; T2_2 Kodab and LAN (T2_2.colB)> LAN (T2_1.colB) is WHERE t2_2.colB faucet;
.
Note that this (possibly) CHARINDEX
query is not possible to use the index (or your original query) index, so for large amounts of data The query may be very slow.
In addition, always test your product data before running SQL updates from random people on the internet :)
Comments
Post a Comment