此错误的其他问题在Access中,但我的查询在Access(2010)中运行正常。
但是,当我打开从Excel(2010)到所述查询的数据连接时,那就是当它遇到“SELECT语句包含拼写错误或缺失的保留字或参数名称,或者标点符号不正确时。 “
如下所示,第一个嵌套的SELECT有一个不可能WHERE 1 = 0
用于定义数据类型,因为我有Nulls。
这就是造成错误的原因。如果我删除它,Excel可以连接(第二组代码)。
但是,作为Excel的保留字,我没有看到任何跳出来的东西。
导致问题的代码段:
SELECT
'A' As Emp
, 1 As [aaa]
, 1 As [bbb]
, 'A' As Definition
, 1 As Month
, 1 As Year
, CCur( 1 ) As costA
, 1 As [ccc]
, 1 As [ddd]
FROM [hereA]
WHERE 1 = 0
我的查询的最短版本,错误:
SELECT Emp, Sum( [bbb] ) AS theB, Sum( [aaa] ) AS theA, Definition, theMonth, theYear, Sum( costA ) AS costB, Count( [ddd] ) AS [theD], Count( [ccc] ) AS [theC]
FROM (SELECT
'A' As Emp
, 1 As [aaa]
, 1 As [bbb]
, 'A' As Definition
, 1 As Month
, 1 As Year
, CCur( 1 ) As costA
, 1 As [ccc]
, 1 As [ddd]
FROM [hereA]
WHERE 1 = 0
UNION ALL SELECT
[h_A].[emp_a] AS Emp
, Int( 0 ) AS [aaa]
, Int( 1 ) AS [bbb]
, 'Text1' AS Definition
, theMonth( [h_A].[date1] ) AS [Month]
, theYear( [h_A].[date1] ) AS [Year]
, [h_A].[thisCost] AS costA
, NULL AS [ccc]
, [foo].[d network] AS [ddd]
FROM
( [hereA] AS [h_A] LEFT JOIN [thereA]
ON [h_A].[dcr] = [thereA].[dcr]
)
LEFT JOIN [foo]
ON [thereA].[s ball*] = [foo].[s ball]
WHERE ( ( [h_A].[date]>=#1/1/2012# ) AND ( Int( [h_A].[indicator] )=1 ) )
) AS AllowGroupBy
GROUP BY Emp, theMonth, theYear, Definition;
答案 0 :(得分:1)
这是该查询的最后一部分。它试图与SELECT
无关联。
UNION ALL SELECT
) AS AllowGroupBy
GROUP BY Emp, theMonth, theYear, Definition;
我很惊讶甚至可以像你声称的那样使用Access。
答案 1 :(得分:0)
事实证明,改变“月”和“年”修复了这个问题,虽然我不知道为什么可以保留,如果我删除了令人不安的部分...因为“月”和“年”仍然在那里。