0

我在 MS ACCESS 数据库中遇到错误“查询值和目标字段的数量不相同”

这是我的查询:

我将此命名为 QryMetrics

SELECT A, B, C, D, E, F
FROM (SELECT count(ID ) as A FROM RelevantResults WHERE Field1 Is Not Null and Field1 <> Chr(13) & Chr(10))  AS Q1,
(SELECT count(ID) as B FROM RelevantResults WHERE Field2 Is Not Null)  AS Q2, 
(SELECT COUNT(ID) as C FROM RelevantResults WHERE Field3 Like '*.jpg' AND Field1 Is Not Null)  AS Q3, 
(SELECT COUNT(ID) as D FROM RelevantResults WHERE Field3 Like '*.jpg' OR Field1 Is Not Null)  AS Q4,
(SELECT COUNT(ID) as E FROM RelevantResults WHERE Field3 Like '*.jpg' OR Field1 Is Not Null OR Field2 Is Not Null)  AS Q5,
(SELECT COUNT(ID) as F FROM RelevantResults WHERE Field3 Like '*.jpg')  AS Q6;

插入查询:

StrSQL = "INSERT INTO metrics (Filename, Field1, Field2, Field3, Field4, Field5, Field6)
Select '" & strFile & "', QryMetrics.* from QryMetrics;"

我在 VB 中使用 DoCmd.RunSQL 执行插入查询。

DoCmd.RunSQL StrSQL

当我尝试在数据库中仅针对 6 个字段运行查询时:我遇到了一个错误:插入语句包含以下未知字段名称:'A'

INSERT INTO metrics (Field1, Field2, Field3, Field4, Field5, Field6)
select  * from qryMetrics

对此有什么想法吗?谢谢

4

2 回答 2

0

这解决了我的问题:

StrSQL = "INSERT INTO metrics (Filename, Field1, Field2, Field3, Field4, Field5, Field6)
Select '" & strFile & "', A, B, C, D, E, F from QryMetrics;"
于 2013-08-03T12:48:55.520 回答
-2
INSERT INTO metrics (Filenae, Field1, Field2, Field3, Field4, Field5, Field6)
Select '" & strFile & "',     -- 1 column
        QryMetrics.*          -- + 6 from QryMetrix
from QryMetrics;              -- = 7 in total

插入中的列列表有 6 列(field1、field2、... field6),
但您的选择返回 7 列。

于 2013-08-03T11:24:00.447 回答