Member_2_7970395
asked on
How To Identify Records From Two Different SQL Tables
I need to identify records (BY THEIR FIRST SIX (6)) digits between two tables. I using the below SQL statement:
SELECT TABLE2.COMPANY_ID AS ACCOUNTS_WITH_A_STATUS, TABLE1.ACCOUNT AS MATCHING_ACCOUNTS
FROM TABLE1
JOIN TABLE2 ON TABLE1.ACCOUNT = TABLE1.ACCOUNT
WHERE TABLE2.STATUS = 'A' AND TABLE2.COMPANY_ID + '%%%%%%' LIKE '%%%%%%' + TABLE1.ACCOUNT + '%%%%%%'
At first, this query seemed to work, however, it seems to be matching the LAST six digits, instead of the FIRST six digits. Please see attachment. Any assistance with this issue would be greatly appreciated.
Sample_1.PNG
SELECT TABLE2.COMPANY_ID AS ACCOUNTS_WITH_A_STATUS, TABLE1.ACCOUNT AS MATCHING_ACCOUNTS
FROM TABLE1
JOIN TABLE2 ON TABLE1.ACCOUNT = TABLE1.ACCOUNT
WHERE TABLE2.STATUS = 'A' AND TABLE2.COMPANY_ID + '%%%%%%' LIKE '%%%%%%' + TABLE1.ACCOUNT + '%%%%%%'
At first, this query seemed to work, however, it seems to be matching the LAST six digits, instead of the FIRST six digits. Please see attachment. Any assistance with this issue would be greatly appreciated.
Sample_1.PNG
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER