插入 INTO NOT EXISTS SQL 访问 [英] Insert INTO NOT EXISTS SQL access

查看:23
本文介绍了插入 INTO NOT EXISTS SQL 访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 sql 将另一个表中的记录插入到 Access 中的表中.我已经粘贴了下面的声明.我想插入存在于 ImportMetricsIDs01262015 但不存在于 ShouldImportMetricsIDs 中的记录.它运行完美,没有任何错误,但即使我物理添加新记录,它也不会插入任何内容.

I am trying to insert records from another table into a table in Access using sql. I have pasted the statement below. I want to insert the records that exist in ImportMetricsIDs01262015 but not in ShouldImportMetricsIDs. It runs perfectly without any errors but it won't insert anything even when I physically add a new record.

INSERT INTO ShouldImportMetricsIDsTable ( [Formulary ID], [Market Segment] )
SELECT ImportMetricsIDs01262015.[Formulary ID], ImportMetricsIDs01262015.[Market Segment]
FROM ImportMetricsIDs01262015
WHERE NOT EXISTS (SELECT *
FROM ShouldImportMetricsIDsTable);

推荐答案

你需要一个关联子句.子查询只是检查表是否为空.比如:

You need a correlation clause. The subquery just checks whether or not the table is empty. Something like:

INSERT INTO ShouldImportMetricsIDsTable( [Formulary ID], [Market Segment] )
    SELECT im.[Formulary ID], im.[Market Segment]
    FROM ImportMetricsIDs01262015 as im
    WHERE NOT EXISTS (SELECT 1
                      FROM ShouldImportMetricsIDsTable as sim
                      WHERE im.[Formulary ID] = sim.[Formulary ID] AND
                            im.[Market Segment] = sim.[Market Segment]
                     );

这篇关于插入 INTO NOT EXISTS SQL 访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆