Reputation: 351
I need an SQL query to map the string content of a column in TableA to a set of columns in TableB. It looks like this:
TableA
| ID | Status |
---------------
| 0 | "full" |
| 1 | "part" |
| | |
TableB
| ID | full | part |expire|
--------------------------
| 0 | true | false| false|
| 1 | false| true | false|
| | | | |
I am using MS Access and currently this is all I've got:
SELECT * FROM TableA INNER JOIN TableB ON TableA.ID = TableB.ID
Which correctly matches the two tables based on ID. However, I do not know where to go from here. Lets say the following is added to TableA:
{ID:2, Status:"Expire"}
How can I map this from TableA to TableB? Ideally this would all be done in 1 query.
Many thanks in advance! :)
Upvotes: 0
Views: 85
Reputation: 171
Your question is not clear enough.
If you want to recreate TableB from TableA then use the IIf ( expr , truepart , falsepart ) function in a query. Example below (added status field - you can exclude it):
Select ID,Status, IIf([Status]="full", true, false) as full, IIf([Status]="part", true, false) as part,IIf([Status]="expire", true, false) as expire from TableA
If you meant to join the two tables then use LEFT OUTER join that will include all rows in TableA. In this case row 3 will have nulls for the boolean flag since there is no matching row.
SELECT TableA.ID,Status,full,part,expire FROM TableA LEFT JOIN TableB ON TableA.ID = TableB.ID
Regards, Bikxs
Upvotes: 1