Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/29.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.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
Sql 查询表达式中的语法错误(缺少运算符)-我在哪里将其括起来?_Sql_Excel_Syntax Error_Left Join_Brackets - Fatal编程技术网

Sql 查询表达式中的语法错误(缺少运算符)-我在哪里将其括起来?

Sql 查询表达式中的语法错误(缺少运算符)-我在哪里将其括起来?,sql,excel,syntax-error,left-join,brackets,Sql,Excel,Syntax Error,Left Join,Brackets,我明白了 “查询表达式中出现语法错误(缺少运算符…” 使用Provider=Microsoft.ACE.OLEDB.12.0从一个Excel电子表格运行此查询到另一个Excel电子表格时 select Distinct [set$].F1 as SETID, [set$].F7 as SetVolume, [tray$].F8 as fracwidth from [set$] Left join [traysinset$] as TS1 on [set$].F1=TS1.F2 Left join

我明白了

“查询表达式中出现语法错误(缺少运算符…”

使用Provider=Microsoft.ACE.OLEDB.12.0从一个Excel电子表格运行此查询到另一个Excel电子表格时

select Distinct [set$].F1 as SETID, [set$].F7 as SetVolume, [tray$].F8 as fracwidth
from [set$]
Left join [traysinset$] as TS1 on [set$].F1=TS1.F2
Left join [traysinset$] as TS2 on TS1.F3=TS2.F2
Left join [tray$] on [tray$].F1=TS1.F3 or [tray$].F1=TS2.F3
where [set$].F1 <>'' and [set$].F1 is not Null and [tray$].F8 <>'' and [tray$].F8 is not Null and [tray$].F8 <>'NULL'
ORDER BY [set$].F1 ASC, [tray$].F8 ASC
选择Distinct[set$].F1作为SETID,[set$].F7作为SetVolume,[tray$].F8作为fracwidth
从[set$]
在[set$]上将[traysinset$]作为TS1左连接。F1=TS1.F2
左连接[traysinset$]作为TS1上的TS2。F3=TS2.F2
在[tray$]上左连接[tray$]。F1=TS1.F3或[tray$]。F1=TS2.F3
其中,[set$].F1''和[set$].F1不为空,[tray$].F8''和[tray$].F8''不为空,[tray$].F8不为空
按[set$].F1 ASC、[tray$].F8 ASC订购
我知道问题出在我的连接上,并尝试过各种括号和嵌套,但似乎无法解决它。我已经在SQLServerManagementStudio中成功地运行了查询,如下所示,因此我真的很难理解为什么它在Excel中不起作用

select Distinct [set].id as SETID, [set].volume as SetVolume, [tray].fracwidth as fracwidth
from [myserver].[dbo].[set]
Left join [myserver].[dbo].[traysinset] as TS1 on [set].id=TS1.setid
Left join [myserver].[dbo].[traysinset] as TS2 on TS1.trayid=TS2.setid
Left join [myserver].[dbo].[tray] on [tray].id=TS1.trayid or [tray].id=TS2.trayid
where [set].id <>'' and [set].id is not Null and [tray].fracwidth <>'' and [tray].fracwidth is not Null and [tray].fracwidth <>'NULL'
ORDER BY [set].id ASC, [tray].fracwidth ASC
选择不同的[set]。id为SETID,[set]。卷为SetVolume,[tray]。fracwidth为fracwidth
从[myserver].[dbo].[set]
将[myserver].[dbo].[traysinset]作为TS1左联合到[set].id=TS1.setid
将[myserver].[dbo].[traysinset]作为TS1上的TS2左连接。trayid=TS2.setid
在[tray].id=TS1.trayid或[tray].id=TS2.trayid上左键加入[myserver].[dbo].[tray]
其中[set].id“”和[set].id不为Null且[tray].fracwidth“”和[tray].fracwidth不为Null且[tray].fracwidth“Null”
订单依据[set]。id ASC,[tray]。分形宽度ASC

非常感谢所有帮助。

不确定解决方案,但您是否打算进行此比较,因为这是在寻找“NULL”作为文本字符串,而不是NULL值:[tray$]。F8“NULL”如果遵循与Access SQL相同的语法,可能需要在连接子句周围嵌套括号,例如<代码>从((T1上的T1左连接t2.field=t2.field)t2上的左连接t3.field=t3.field)t3上的左连接t4.field=t4.field。我会使用Access查询生成器获取正确的语法,然后将其移植到Excel VBA。这是否回答了您的问题?你在哪里证明你所写的符合手册中的语法?如果你不能证明它的合理性,你为什么要写它?(修辞)PS当代码有错误时,把它切碎直到它没有。感谢6月7日的帮助。使用正确的括号,我已将问题缩小到我的或语句中,选择Distinct[set$].F1作为SETID,[set$].F7作为SetVolume,[tray$].F8作为fracwidth,从(([set$]左连接[traysinset$]作为[set$]上的TS1.F1=TS1.F2)左连接[traysinset$]作为TS1上的TS2.F3=TS2.F2)左连接[tray$]作为[tray$].F1=TS1.F3,其中[set$].F1]和[set$].F1不为空且[TARY$].F8''和[TARY$].F8不为空且[TARY$].F8按[set$].F1 ASC、[TARY$].F8 ASC排序。此操作正常,但我需要最后一个联接为[TARY$].F1=TS1.F3或[TARY$].F1=TS2.F3