I have 4 tables.
table: Account
| AccountName | AccountID | Sales | Products |
|---|---|---|---|
| CVSID | 123345tf | 6573 | A, C, T, Y |
| WALGREENID | 6482639w | 4739 | A, U, p, Y |
| uthalID | 2638949w | 45632 | I, Y, O, P |
| uhdhoID | 7362646w | 97474 | A, C, P, Y |
Account-ICM
| AccountName | AccountID | Sales | Products |
|---|---|---|---|
| WALGREENID | 6482639w | 4739 | A, U, p, Y |
| uthalID | 2638949w | 45632 | I, Y, O, P |
| uhdhoID | 7362646w | 97474 | A, C, P, Y |
Account_WP
| AccountName | AccountID | Sales | Products |
|---|---|---|---|
| CVSID | 123345tf | 6573 | A, C, T, Y |
Account_S
| AccountName | AccountID | Sales | Products |
|---|---|---|---|
| CVSID | 123345tf | 6573 | A, C, T, Y |
| uthalID | 2638949w | 45632 | I, Y, O, P |
I am trying to write a for loop which will check if ACCOUNTID from Accounts table is present in ACCOUNT_ICM, ACCOUNT_WP, and ACCOUNT_S.
If the AccountID of Accounts table is found in ACCOUNT_ICM tables, then add a column in Accounts tables with heading as ICM and value 1 for the accountID which is present in ICM table else 0.
This is the output I want
| AccountName | AccountID | Sales | Products | ICM | WP | S |
|---|---|---|---|---|---|---|
| CVSID | 123345tf | 6573 | A, C, T, Y | 0 | 1 | 1 |
| WALGREENID | 6482639w | 4739 | A, U, p, Y | 1 | 0 | 0 |
| uthalID | 2638949w | 45632 | I, Y, O, P | 1 | 0 | 1 |
| uhdhoID | 7362646w | 97474 | A, C, P, Y | 1 | 0 | 0 |