使用来自另一个涉及唯一字段的 table 的值插入 table

Inserting into table using values from another table involving a unique filed

给我带来问题的字段是 tbl1 上名为 ItemNounique required 字段。我想从 tbl2 复制 ItemNo 字段值并将其添加到 tbl1 ItemNo 字段,但在字符串末尾添加 D 。所有 ItemNo 字段的格式为 Text

tbl1 目前看起来像:

ID   ItemNo   ItemDescription   ....
1    001      Epoxy resin       ....
2    002      Wood glue         ....

tbl2 目前看起来像:

ID   ItemNo   ItemDescription   ....
1    001      Epoxy resin       ....
2    002      WD40              ....

预计 tb1 更新后看起来像:

ID   ItemNo   ItemDescription   ....
1    001      Epoxy resin       ....
2    002      Wood glue         ....
3    001D     Epoxy resin       ....
4    002D     WD40              ....

可能是这样的:

CurrentDB.Execute "INSERT INTO tbl1 SELECT * FROM tbl2 ...."

我可以使用 DAO 完成任务,但想知道是否也可以使用 SQL。

Dim rs1 As DAO.Recordset
Dim rs2 As DAO.Recordset
Set rs1 = CurrentDb.OpenRecordset("SELECT*FROM tbl1")
Set rs2 = CurrentDb.OpenRecordset("SELECT*FROM tbl2")

With rs2
.MoveFirst
Do Until rs2.EOF
rs1.AddNew
rs1.Fields("ItemNo").Value = rs2.Fields("ItemNo").Value & "D"
....
....
rs1.Edit
rs1.Update
rs2.MoveNext
Loop
End With
rs1.Close
Set rs1 = Nothing
rs2.Close
Set rs2 = Nothing

嗯。 . .你似乎想要:

insert into tbl1 (itemNo, itemDescription)
    select itemNo & 'd', itemDescription
    from tbl2;

这假定 id 是自动分配的。