Question

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".

If I replace the sub-query with a static "WHERE TRAN_NUMBER IN (0,1,2,3..)" it returns the expected values. 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

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

Additional information: ODBC--call failed

Edit: Looks like Subqueries don't work when linked to another database via ODBC (The original database is a SageLine50 database). 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?

Was it helpful?

Solution

Instead of using an IN clause and a subquery you could try a 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).

That is certainly not true for all ODBC linked tables. 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. (Mine does, too.) Your issue is almost certainly caused by a deficiency in the SageLine50 ODBC driver.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top