Advertisement

05.08.2008 at 08:03PM PDT, ID: 23388319
[x]
Attachment Details

Difficulty in pulling data from AS400 databases using Excel query with a complex SQL statement

Asked by lundca in Microsoft Excel Spreadsheet Software, Programming for iSeries / AS400, VB Database Programming

I'm using the section of code listed here to pass a SQL statement in the strQry variable.  I can pull simple data such as:

"Select * From MyLibrary.MyTable Where FieldX = 'Value' Order By FieldX"

But if I do something like

"SELECT MyTable.FieldA, MyTable.FieldB, MyTable.FieldC FROM MyLibrary/MyTable INNER JOIN MyLibrary/MyTable2 ON MyTable.FieldA=MyTable2.FieldA"

I get a "Run Time Error '1004' General ODBC Error"

Can I pass complex SQL statements to an AS400 iSeries ODBC driver?  Or is there a particular syntax different from what, say, MS Access would recognize in a SQL statement?
Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
With ActiveSheet.QueryTables.Add(Connection:="ODBC;DSN=AS400;", Destination _
     :=Range("A7"))
    .CommandText = strQry
        .Name = "Query from AS400"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = True
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .PreserveColumnInfo = True
        .Refresh BackgroundQuery:=False
End With
[+][-]05.08.2008 at 08:46PM PDT, ID: 21530296

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Excel Spreadsheet Software, Programming for iSeries / AS400, VB Database Programming
Sign Up Now!
Solution Provided By: _b_h
Participating Experts: 2
Solution Grade: A
 
 
[+][-]05.09.2008 at 02:44AM PDT, ID: 21531359

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.09.2008 at 06:54AM PDT, ID: 21532797

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.09.2008 at 07:58AM PDT, ID: 21533497

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628