Link to home
Start Free TrialLog in
Avatar of Member_2_7970395
Member_2_7970395

asked on

How To Delete Mutiple Records Found Be

I will try to make this as clear as possible.  My main objective is to "Identify" and then "Delete" records found between two tables.  I've solved the first part of "Identifying" the records that needs to be deleted, however, I'm a little stuck on how to delete the 370K records found.  The below query is what I use to locate the records:  It works fine.

SELECT TABLE1.COLUMN1 AS ACCOUNTS, TABLE2.COLUMN1 AS COMPANY_HQ
FROM TABLE1, TABLE2
WHERE TABLE1.ACCOUNT + '%%%%%%' LIKE '%%%%%%' + TABLE2.COMPANY_HQ + '%%%%%%'
ORDER BY TABLE2.COMPANY_HQ ASC;

(see attached file for results)

Now...I'm using the below query to delete the records found in Table2:

DELETE FROM TABLE2
WHERE TABLE2.ACCOUNT + '%%%%%%' LIKE '%%%%%%' + TABLE1.COMPANY_HQ + '%%%%%%'

BUT...I get the below error message:

Msg 4104, Level 16, State1, Line 2
The multi-part identifier "TABLE2.COMPANY_HQ" could not be bound.

I apologize for any confusion.  Any assistance in this matter would be greatly appreciated.
SQL-Result.PNG
SOLUTION
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Member_2_7970395
Member_2_7970395

ASKER

It worked!  Thank you very much!!
Don't if I'm entering this correctly, but if not, I want to THANK all of you who responded.
Glad we could help.

Looks like you're trying to close this question. I think they've made that more confusing. You can either click "Close Question" at the bottom of your browser or click "Best Answer" in the comment you want to accept. You can then edit to accept multiple solutions.

Happy SQLing!