我是SQL的新手,正在尝试创建一个收集以下内容的字符串:
下面的代码不断给我一个 From子句中的语法错误。我假设这与我在INNER JOINS上的括号有关,但我不确定。
在添加第二个INNER JOIN子句(外部数据库)之前,此代码运行良好,我的WHERE&ORDER BY子句运行良好。
sqlProd = "SELECT c.Code," _
& " p.Description, p.weight, p.[Pack Size], p.PPB, p.[CP-UK], p.[CP-EU]," _
& " pl.1" _
& " FROM ([Catalogue Info] c" _
& " INNER JOIN [Product Information] p" _
& " on c.code = p.code)" _
& " INNER JOIN [;database=C:\mypath\db.accdb;PWD=password123].table_name pl" _
& " on c.code = pl.code" _
& " WHERE c.Sub_Cat_1 = '" & rstSub1!Sub_Cat_1 & "'" _
& " AND c.Sub_Cat_2 = '" & rstSub2!Sub_Cat_2 & "'" _
& " ORDER BY c.Page ASC, c.Page_Position ASC;"
有什么想法吗?
Access 2016,Excel 2016,Windows 10
谢谢! Dom
答案 0 :(得分:0)
我认为这应该可行,因为我认为您的FROM
子句的一部分有不必要的括号:
sqlProd = "SELECT c.Code," _
& " p.Description, p.weight, p.[Pack Size], p.PPB, p.[CP-UK], p.[CP-EU]," _
& " pl.1" _
& " FROM [Catalogue Info] c" _
& " INNER JOIN [Product Information] p" _
& " on c.code = p.code" _
& " INNER JOIN [;database=C:\mypath\db.accdb;PWD=password123].table_name pl" _
& " on c.code = pl.code" _
& " WHERE c.Sub_Cat_1 = '" & rstSub1!Sub_Cat_1 & "'" _
& " AND c.Sub_Cat_2 = '" & rstSub2!Sub_Cat_2 & "'" _
& " ORDER BY c.Page ASC, c.Page_Position ASC;"
答案 1 :(得分:0)
我想我已经找到了解决方案-不是括号,而是我使用的密码。
我使用的密码(不是原始问题)使用了特殊字符(#>`{(= ),这似乎是语法错误。我将Access数据库中的密码更改为字母/ numbers,原始代码可以正常工作。
希望这可以帮助其他人。最终代码:
sqlProd = "SELECT c.Code," _
& " p.Description, p.weight, p.[Pack Size], p.PPB, p.[CP-UK], p.[CP-EU]," _
& " pl.[1]" _
& " FROM [Catalogue Info] as c" _
& " INNER JOIN [Product Information] as p" _
& " on c.code = p.code" _
& " INNER JOIN [;database=C:\mypath\db.accdb;PWD=password123].table_name as pl" _
& " on c.code = pl.code" _
& " WHERE c.Sub_Cat_1 = '" & rstSub1!Sub_Cat_1 & "'" _
& " AND c.Sub_Cat_2 = '" & rstSub2!Sub_Cat_2 & "'" _
& " ORDER BY c.Page ASC, c.Page_Position ASC;"
感谢您的反馈。