查询将id插入另一个表

时间:2017-08-22 18:34:38

标签: sql ms-access

我有一张表批准

+----+----------+
| ID |   Name   |
+----+----------+
|  1 | Approved |
|  2 | Rejected |
|  3 | On Hold  |
+----+----------+

我将表格Approvals的“id”存储在另一个表预算中,如下所示:

+-----+-----------+--------+
| BID | RequestID | Status |
+-----+-----------+--------+
| 101 |   2228484 |      1 |
| 102 |   3834848 |      2 |
+-----+-----------+--------+

1 = Approved
2 = Rejected

我从excel电子表格导入预算数据,该电子表格包含文本形式的批准状态。以下示例

+-----+-----------+----------+
| BID | RequestID |  Status  |
+-----+-----------+----------+
| 101 |   2228484 | Approved |
| 102 |   3834848 | Rejected |
+-----+-----------+----------+

我是否有办法从表Approvals中获取excel导入的相关状态ID并将其插入表Budget?

1 个答案:

答案 0 :(得分:1)

INSERT INTO Budget (BID,RequestID,Status)
SELECT i.BID, i.RequestID, a.ID as Status
FROM Import_Table i
INNER JOIN Approvals a
  ON i.Status = a.Name