与此错误有关的其他问题在 Access 中,但我的查询在 Access (2010) 中运行良好。
但是,当我打开从 Excel (2010) 到所述查询的数据连接时,就会出现“SELECT 语句包含拼写错误或丢失的保留字或参数名称,或者标点符号不正确”。
正如您在下面看到的,第一个嵌套的 SELECT 有一个不可能WHERE 1 = 0
用于定义数据类型,因为我在哪里有 Null。
这就是导致错误的原因。如果我删除它,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;