My request is a little strange and specific, please bear with me.
I have an Access 2003 database with a Comments
table that has several hundred thousand lines in it. There are several fields - let's call them A, B, C, D
and comment
. Columns A-C
form the PK of the table. Thus, you could have 5, 10, or 50 rows which have different comments, but all pertain to the A-C
PK.
I have another table called CORE
which contains a table core
that has fields A, B, C, D
(A-C
PK) and comment_value_insert
.
What I want to do:
In Comments
, for each "set" of identical A-C
rows (Field D
can differ), if none of their comment
values matches a certain value (let's call it critical
), then look up the same row in CORE
and insert into the comments
table a new row with A-D
and Comments.comment = core.comment_value_insert
.
I'm not even sure if this is possible with SQL (perhaps VBA? Hence the tag). Any advice anyone?
For further clarification please ask away.
Huge thanks in advance.
EDIT
To demonstrate exactly what I want:
If my Comments
table looks like
A | B | C | D | Comment
1 2 3 b val1
1 2 3 x val2
1 2 3 a val3
2 9 8 z val4
2 9 8 a val5
3 3 3 x val6
END
And my CORE
Table looks like
A | B | C | D | Comment_value_insert
1 2 3 u critical1
2 9 8 t critical2
4 8 6 x critical3
END
Then I'd want the critical1
row from CORE
to be inserted into Comments
, as well as the critical2
row, but not the critical3
row.
Then the final product in the Comments
table will be
A | B | C | D | Comment
1 2 3 b val1
1 2 3 x val2
1 2 3 a val3
1 2 3 u critical1
2 9 8 z val4
2 9 8 a val5
2 9 8 t critical2
3 3 3 x val6
END