插入不存在的SQL访问权限 [英] Insert INTO NOT EXISTS SQL access
本文介绍了插入不存在的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]
);
这篇关于插入不存在的SQL访问权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文