Skip to content
Advertisement

How to help implement more logic in my joins?

I have some logic currently in my sql statement that takes away all punctuation so I can compare the two fields easily; however, I am having an issue now where my A table has a bank name of BBVA BANCOMER SA INSTITUCION DE BANCA MULTIPLE, GRUPO FINANCIERO BBVA BANCOMER and my B table has the Institution name of, BBVA BANCOMER and other variations that do not match Table A.

I have multiple different bank names with this issue.

How do I add a like '%<bank name here>%' into my join to find all the matches? Thank you.

I was thinking maybe a WHERE clause; however, I don’t know how to compare the two fields together based on a LIKE function. If I found a solution for this, would I need to do the same for each bank needed?


I am currently getting 31 matches soley based off of taking punctuation out; however, my expected output is above 1,650. This is because BANCOMER has no matches anywhere solely based on exact name, however, when I go into Table B database, there are ~1600 outputs for LIKE '%BANCOMER%'. I need to implement a LIKE function.

Advertisement

Answer

I think what you need is a lookup table that gives you like values. Then you can populate that table in a way that drives your business rules.

For example consider the following LOOKUP table.

Then you can have a query like this:

Now we have A and B joining on BOA = BANK OF AMERICA and CITIBANK = CITI

You can continue to add new entities to the LOOKUP table as you “find” them and want them to join together.

Using a lookup table in this way on SQL servers is much faster than running a function (or multiple) like you are in the sample code.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement