Microsoft Access/SQL 错误参数框
Posted
技术标签:
【中文标题】Microsoft Access/SQL 错误参数框【英文标题】:Microsoft Access/SQL Mistaken Parameter Box 【发布时间】:2014-05-05 16:30:40 【问题描述】:我在 MS Access 2010 中工作,以便能够使用我们存储在专有数据库中的数据运行我自己的查询/报告。我将此查询编写为两个子查询,每个子查询都可以完美地独立运行。但是,当我一起运行它们时,我得到一个参数输入框,说我需要为 Query4.company_id 输入一个参数。我仔细检查了拼写错误,所以情况似乎并非如此。我认为我的子查询连接到我的主查询的方式一定有问题。我是一个新手,但很高兴得到您的任何建议!这是我的查询:
选择 dbo_Companies.company_id、dbo_Companies.company_name、dbo_Lease.lease_from_dt、dbo_Lease.lease_to_dt、dbo_Lease.lease_status、dbo_Lease.lease_description、dbo_Companies.company_status
从 dbo_Companies 左加入 dbo_Lease ON dbo_Companies.company_id = dbo_Lease.company_id
在哪里(((dbo_Companies.company_id)在
(SELECT dbo_Companies.company_id
FROM (dbo_Companies INNER JOIN dbo_CompanyFacilities ON dbo_Companies.company_id = dbo_CompanyFacilities.company_id) INNER JOIN dbo_Facilities ON dbo_CompanyFacilities.facility_id = dbo_Facilities.facility_id
WHERE (((dbo_CompanyFacilities.facility_id)=11 或 (dbo_CompanyFacilities.facility_id)=13 或 (dbo_CompanyFacilities.facility_id)=14 或 (dbo_CompanyFacilities.facility_id)=15 或 (dbo_CompanyFacilities.facility_id)=21 或 (dbo_CompanyFacilities.facility_id)=28 或 (dbo_CompanyFacilities.facility_id)=24 或 (dbo_CompanyFacilities.facility_id)=27 或 (dbo_CompanyFacilities.facility_id)=31 或 (dbo_CompanyFacilities.facility_id)=32 或 (dbo_CompanyFacilities.facility_id)=33 或 (dbo_CompanyFacilities.facility_id)=37) AND (dbo_Companies.company_status = "Active") AND (((dbo_Companies.company_class_id)=1) OR ((dbo_Companies.company_class_id)= 14))))));
【问题讨论】:
【参考方案1】:试试这个:
SELECT
C.company_id,
C.company_name,
L.lease_from_dt,
L.lease_to_dt,
L.lease_status,
L.lease_description,
C.company_status
FROM dbo_Companies C
LEFT JOIN dbo_Lease L
ON C.company_id = L.company_id
WHERE C.company_id IN
(SELECT C2.company_id
FROM dbo_Companies C2
INNER JOIN dbo_CompanyFacilities CF
ON C2.company_id = CF.company_id
INNER JOIN dbo_Facilities F
ON CF.facility_id = F.facility_id
WHERE
CF.facility_id IN (11, 13, 14, 15, 21, 28, 24, 27, 31, 32, 33, 37)
AND C2.company_status = "Active"
AND C2.company_class_id IN (1, 14)
);
要对此进行测试,请先运行第二个 SELECT 语句(括号内的那个)并查看是否得到任何结果。如果是这样,请运行整个代码块,看看是否仍然出现该错误。在对数据一无所知的情况下,它看起来应该可以正常运行。
【讨论】:
非常感谢您的回答!运行第二个 SELECT 语句时,MS Access 向我抛出了一个语法错误(缺少运算符),处理后半部分的 FROM 部分。我也会继续寻找和修补——你的指导真的很有帮助。以上是关于Microsoft Access/SQL 错误参数框的主要内容,如果未能解决你的问题,请参考以下文章
使用 Access SQL 函数时,Microsoft Access ODBC 驱动程序导致访问冲突