And what I'd like to achieve, is to first: Get the length of the values for Column B and use it for further queries.
Second: If I have the length for each record, search for that specific record going backwards in column A and see if there's match with a partition on column A.
I tried to visualize here:
We're checking if Column B has values that can be found in Column A, but only as the last few digits of it. And that amount of digits is based on the length of Column B's value.
So I have "abcde" for Column B, which is 5 characters long. What I'm looking for, is if we have "abcde" as the ending 5 characters of Column A values, for example if we have this value: kdjf_dabcde, then it's a match, because the last 5 characters are matching.
Or another example: "bckLdjskd2" in Column B, which is 10 characters long. Now we're looking at the last 10 digits of Column A, and checking if we have this value, for example: "13K-Ldh:bckLdjskd2", here's a match, because no matter what Column A's first X values, if the last 10 matches with column B.
select
columnA
, columnB
, case when columnA like '%'+columnB then 'match because the record ('+columnB+') length in columnB is '+cast(len(columnB) as varchar) +' can be found as last '+cast(len(columnB) as varchar)+' characters of columnA'
else ' NO MATCH because the record ('+columnB+') length in columnB is '+cast(len(columnB) as varchar) +' cannot be found as last '+cast(len(columnB) as varchar)+' characters of columnA'
end
from
#Data
That additional column is basically just an explanation why it’s considered a matching value, the end result should only be a number, which is the amount of matches, so just a “2”.