Have a 2 table with 23 fileds. The field1 of table1 and table2 have a unique id.
I want to insert from table1 to table2 only the records not found base the filed1.
I effect i wanto match all unique id of table1 with unique id from the table2.
How to via vbcode and adojet????
INSERT only the line not found
-
- Administrator
- Posts: 78391
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: INSERT only the line not found
Execute the following SQL string:
strSQL = "INSERT INTO Table2 SELECT * FROM Table1 WHERE Table1.ID Not In (SELECT Table2.ID FROM Table2)"
Substitute the correct names of Table1, Table2 and the ID field.
strSQL = "INSERT INTO Table2 SELECT * FROM Table1 WHERE Table1.ID Not In (SELECT Table2.ID FROM Table2)"
Substitute the correct names of Table1, Table2 and the ID field.
Last edited by HansV on 04 May 2010, 13:52, edited 1 time in total.
Reason: to correct omission (Table.ID > Table2.ID)
Reason: to correct omission (Table.ID > Table2.ID)
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4343
- Joined: 26 Apr 2010, 17:36
Re: INSERT only the line not found
HansV wrote:Execute the following SQL string:
strSQL = "INSERT INTO Table2 SELECT * FROM Table1 WHERE Table1.ID Not In (SELECT Table.ID FROM Table2)"
Substitute the correct names of Table1, Table2 and the ID field.
(SELECT Table.ID FROM Table2)"
Table is table2?
-
- Administrator
- Posts: 78391
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- PlatinumLounger
- Posts: 4343
- Joined: 26 Apr 2010, 17:36
Re: INSERT only the line not found
PROB....HansV wrote:Yes, sorry.
In in the table tath recive the new records in ID have a value complete but in table for mathching i need to join 2 filed to make the unique ID
-
- Administrator
- Posts: 78391
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: INSERT only the line not found
Please provide enough details for us to understand the problem. Thanks in advance.
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4343
- Joined: 26 Apr 2010, 17:36
Re: INSERT only the line not found
sorry for my bad enghlish!HansV wrote:Please provide enough details for us to understand the problem. Thanks in advance.
In effect in table1 have ID="1234567890" instead in table2 have the matching is a from joint from filed1&filed2 similar filed1=12345 filed2=67890....
I hope understand now, sorry.
-
- Administrator
- Posts: 78391
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: INSERT only the line not found
Try
strSQL = "INSERT INTO Table2 SELECT * FROM Table1 WHERE Table1.ID Not In (SELECT Table2.Field1 & Table2.Field2 FROM Table2)"
If the fields of Table1 and Table2 are not identical, you may have to specify them explicitly:
strSQL = "INSERT INTO Table2 (Field3, Field4, Field5, Field6) SELECT FieldA, FieldB, FieldC, FieldD FROM Table1 WHERE Table1.ID Not In (SELECT Table2.Field1 & Table2.Field2 FROM Table2)"
substituting the appropriate names.
strSQL = "INSERT INTO Table2 SELECT * FROM Table1 WHERE Table1.ID Not In (SELECT Table2.Field1 & Table2.Field2 FROM Table2)"
If the fields of Table1 and Table2 are not identical, you may have to specify them explicitly:
strSQL = "INSERT INTO Table2 (Field3, Field4, Field5, Field6) SELECT FieldA, FieldB, FieldC, FieldD FROM Table1 WHERE Table1.ID Not In (SELECT Table2.Field1 & Table2.Field2 FROM Table2)"
substituting the appropriate names.
Best wishes,
Hans
Hans