Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
查询表达式VBA中的语法错误(缺少运算符)_Vba_Excel - Fatal编程技术网

查询表达式VBA中的语法错误(缺少运算符)

查询表达式VBA中的语法错误(缺少运算符),vba,excel,Vba,Excel,当我想要运行我的查询时,我收到一条错误消息(查询表达式中的语法错误(缺少运算符))。我不知道问题出在哪里 我已经创建了一个宏(VBA),它应该显示我公司的所有经理级别 列应如下所示: 最高管理者、董事、经理、团队领导、主管、员工 我认为您只需要添加一些括号,并且不要同时使用别名和实际表名: query = "SELECT L1.[Supervisor ID] AS N0, L1.[Emplid] AS N1, L2.[Emplid] AS N2, L3.[Emplid] AS N3, " &am

当我想要运行我的查询时,我收到一条错误消息(查询表达式中的语法错误(缺少运算符))。我不知道问题出在哪里

我已经创建了一个宏(VBA),它应该显示我公司的所有经理级别

列应如下所示:

最高管理者、董事、经理、团队领导、主管、员工


我认为您只需要添加一些括号,并且不要同时使用别名和实际表名:

query = "SELECT L1.[Supervisor ID] AS N0, L1.[Emplid] AS N1, L2.[Emplid] AS N2, L3.[Emplid] AS N3, " & _
        "L4.[Emplid] AS N4, L5.[Emplid] AS N5, L6.[Emplid] AS N6, L7.[Emplid] AS N7 FROM ((((([DEU1$] L1 " & _
        "LEFT JOIN [DEU1$] L2 ON L1.[Emplid] = L2.[Supervisor ID]) " & _
        "LEFT JOIN [DEU1$] L3 ON L2.[Emplid] = L3.[Supervisor ID]) " & _
        "LEFT JOIN [DEU1$] L4 ON L3.[Emplid] = L4.[Supervisor ID]) " & _
        "LEFT JOIN [DEU1$] L5 ON L4.[Emplid] = L5.[Supervisor ID]) " & _
        "LEFT JOIN [DEU1$] L6 ON L5.[Emplid] = L6.[Supervisor ID]) " & _
        "LEFT JOIN [DEU1$] L7 ON L6.[Emplid]=L7.[Supervisor ID];"

您不能将
L1
etc同时用作字段别名和表别名…您好,我更改了列名,例如:选择L1.[DEU1$].[Supervisor ID]作为N0,选择L1.[DEU1$].[Emplid]作为N1等等,但仍然存在相同的错误。请使用您现在拥有的内容更新问题中的代码。我已更新查询。
query = "SELECT L1.[Supervisor ID] AS N0, L1.[Emplid] AS N1, L2.[Emplid] AS N2, L3.[Emplid] AS N3, " & _
        "L4.[Emplid] AS N4, L5.[Emplid] AS N5, L6.[Emplid] AS N6, L7.[Emplid] AS N7 FROM ((((([DEU1$] L1 " & _
        "LEFT JOIN [DEU1$] L2 ON L1.[Emplid] = L2.[Supervisor ID]) " & _
        "LEFT JOIN [DEU1$] L3 ON L2.[Emplid] = L3.[Supervisor ID]) " & _
        "LEFT JOIN [DEU1$] L4 ON L3.[Emplid] = L4.[Supervisor ID]) " & _
        "LEFT JOIN [DEU1$] L5 ON L4.[Emplid] = L5.[Supervisor ID]) " & _
        "LEFT JOIN [DEU1$] L6 ON L5.[Emplid] = L6.[Supervisor ID]) " & _
        "LEFT JOIN [DEU1$] L7 ON L6.[Emplid]=L7.[Supervisor ID];"