[英]Subquery not working with Access linked tables
I'm attempting to build a tool that pulls information from a database containing financial information, but I've hit a wall with this problem. 我正在尝试构建一个从包含财务信息的数据库中提取信息的工具,但是我遇到了这个问题。 The following query would give me some of the data I require, but as soon as I add in the sub-query, I get the error message
以下查询将为我提供一些我需要的数据,但是一旦在子查询中添加,我就会收到错误消息
"ODBC--call failed".
“ ODBC –调用失败”。
If I replace the sub-query with a static "WHERE TRAN_NUMBER IN (0,1,2,3..)"
it returns the expected values. 如果我用静态的
"WHERE TRAN_NUMBER IN (0,1,2,3..)"
替换子查询,它将返回期望值。 The sub-query returns the expected values when run by itself. 子查询本身运行时返回期望值。
I'm using MS Access and C# and the OleDB library to do this 我正在使用MS Access和C#和OleDB库来执行此操作
Any Ideas what I've done incorrectly? 任何想法我做错了什么?
SELECT NOMINAL_CODE, DETAILS, AMOUNT, TYPE
FROM AUDIT_JOURNAL
WHERE TRAN_NUMBER IN
(SELECT AUDIT_TRAIL_ID
FROM PROJECT_TRAN
WHERE AUDIT_TRAIL_ID > 0);
A first chance exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll
类型“ System.Data.OleDb.OleDbException”的第一次机会异常发生在System.Data.dll中
Additional information: ODBC--call failed
附加信息:ODBC--调用失败
Edit: Looks like Subqueries don't work when linked to another database via ODBC (The original database is a SageLine50 database). 编辑:当通过ODBC链接到另一个数据库时,子查询看起来不起作用(原始数据库是SageLine50数据库)。 I've imported the tables statically and it seems to work.
我已经静态导入了表,它似乎可以工作。 Does anyone know how I can make this work without statically importing the tables?
有谁知道我如何在不静态导入表的情况下完成这项工作?
Instead of using an IN clause and a subquery you could try a JOIN 代替使用IN子句和子查询,您可以尝试JOIN
SELECT
aj.NOMINAL_CODE,
aj.DETAILS,
aj.AMOUNT,
aj.TYPE
FROM
AUDIT_JOURNAL AS aj
INNER JOIN
PROJECT_TRAN AS pt
ON aj.TRAN_NUMBER = pt.AUDIT_TRAIL_ID
WHERE pt.AUDIT_TRAIL_ID > 0
re: your comment in the edit to your question 回复:您对问题的编辑中的评论
Looks like Subqueries don't work when linked to another database via ODBC (The original database is a SageLine50 database).
通过ODBC链接到另一个数据库时,子查询看起来不起作用(原始数据库是SageLine50数据库)。
That is certainly not true for all ODBC linked tables. 对于所有 ODBC链接表肯定不是这样。 I created tables [AUDIT_JOURNAL] and [PROJECT_TRAN] in SQL Server 2008 R2, created linked tables in Access 2010, and your original query works fine in Access.
我在SQL Server 2008 R2中创建了表[AUDIT_JOURNAL]和[PROJECT_TRAN],在Access 2010中创建了链接表,并且原始查询在Access中工作正常。 (Mine does, too.) Your issue is almost certainly caused by a deficiency in the SageLine50 ODBC driver.
(我的也是。)您的问题几乎可以肯定是由SageLine50 ODBC驱动程序缺陷引起的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.