提问人:Noa Zakai 提问时间:7/22/2023 最后编辑:marc_sNoa Zakai 更新时间:7/27/2023 访问量:44
System.Data.OleDb.OleDbException - sql 中的语法错误
System.Data.OleDb.OleDbException - syntax error in sql
问:
我在这个 SQL 中有一个语法错误:
string sSql = $"SELECT OxygenTankInDetailTBL.HBedNameID,
OxygenTankInDetailTBL.LocationHB
FROM OxygenTankInDetailTBL
INNER JOIN SectionsNameTBL ON (SectionsNameTBL.SectionID = OxygenTankInDetailTBL.LocationHB
AND SectionsNameTBL.LocationG = '{locationG}')
INNER JOIN OxygenTankTBL ON (OxygenTankTBL.HBedID = OxygenTankInDetailTBL.HBedNameID
AND OxygenTankTBL.IsActive= {true});";
错误是:
System.Data.OleDb.OleDbException: '查询表达式中的语法错误(缺少运算符)'(SectionsNameTBL.SectionID = OxygenTankInDetailTBL.LocationHB AND SectionsNameTBL.LocationG = 'agaf1') INNER JOIN OxygenTankTBL ON(OxygenTankTBL.HBedID = OxygenTankInDetailTBL.HBedNameID AND OxygenTankTBL.IsActive= True'.'
谢谢
答:
0赞
ValNik
7/27/2023
#1
如果 DBMS 是 MS Access,请参阅此示例。
我想,您可以在 JOIN 操作中加入 1 个表或 subQuery。将其他联接包装在子查询中。
SELECT *
FROM SectionsNameTBL
RIGHT JOIN (
OxygenTankTBL RIGHT JOIN OxygenTankInDetailTBL
ON OxygenTankTBL.HBedID = OxygenTankInDetailTBL.HBedNameID
)
ON SectionsNameTBL.SectionID = OxygenTankInDetailTBL.LocationHB
WHERE SectionsNameTBL.LocationG = 'agaf1'
AND OxygenTankTBL.IsActive= true
;
评论
mysql
postgresql
sql-server
oracle
db2
OxygenTankTBL.IsActive= True