访问vba中的多个select语句

时间:2014-12-17 20:30:54

标签: sql vba ms-access select count

我试图在表中插入2个计数作为一个通过vba访问的记录,并且由于某种原因它说我尝试运行时查询值和目标字段的数量不一样。我很困惑为什么会这样。任何帮助将不胜感激

TotalVerified = " INSERT INTO Totals([TOTAL VERIFIED FORMULARIES], [TOTAL AVAILABLE FOR IMPORT]) " & _
"SELECT COUNT([FORMULARY ID]) " & _
"FROM VerifiedFormularies " & _
"AND COUNT([FORMULARY ID])" & _
"FROM ImportMetricsIDs"

1 个答案:

答案 0 :(得分:0)

我认为您想要的查询是:

INSERT INTO Totals([TOTAL VERIFIED FORMULARIES], [TOTAL AVAILABLE FOR IMPORT]) 
    SELECT CNT1, CNT2
    FROM (SELECT COUNT([FORMULARY ID]) as CNT1 FROM VerifiedFormularies) as c1 CROSS JOIN
         (SELECT COUNT([FORMULARY ID]) as CNT2 FROMImportMetricsIDs) as c2;

AND是一个布尔运算符,通常用于WHERE子句,ON子句或iif()表达式。它没有连接两个子查询中的值。