RE: AS400/DB2 Problem with Group By clause

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Darrell Wesley (DarrellWesley_at_discussions.microsoft.com)
Date: 06/30/04


Date: Wed, 30 Jun 2004 15:00:01 -0700

Found problem. BUT for all of those AS400 experts what is the best way to handle a query with a Group By clause that you are attempting to also bring back data that does not need to be in an aggegate. Like in this query the first 3 fields represent the PO number, PO line and PO date and what Id like to do is to sum the shipqtys together for each PO and Line keeping the original PO date in the output.

In order to solve this I've arbitrarily added the max function to the other fields just to satisfy the query syntax. Is there something better to use?

"Darrell Wesley" wrote:

> With the following query every thing is fine but when I add a Group By clause I get a strange error. Need help help in resolving what the problem is.
>
> SQL = "Select OHBPO#, DIPOLN, DIPODT, ODPN, O8BTPN,"
> SQL = SQL & " EO6DES, ODORGQ, O6CRQM, O6CRQY, OHORDD, ODSHPD,"
> SQL = SQL & " ODSHPQ AS SHIPQTY, CMCITY, ODCARR from ERMTST010.O4ER7"
>
> With adoConn
> .ConnectionString = AS400CONN
> .Open
> End With
> With adoCD
> .CommandText = SQL
> .CommandTimeout = 120
> .CommandType = adCmdText
> .ActiveConnection = adoConn
>
> End With
> Set adoRS = adoCD.Execute
>
> Adding the GROUP BY clause:
>
> SQL = "Select OHBPO#, DIPOLN, DIPODT, ODPN, O8BTPN,"
> SQL = SQL & " EO6DES, ODORGQ, O6CRQM, O6CRQY, OHORDD, ODSHPD,"
> SQL = SQL & " SUM(ODSHPQ) AS SHIPQTY, CMCITY, ODCARR from ERMTST010.O4ER7"
> SQL = SQL & " GROUP by OHBPO#, DIPOLN "
>
> The following error is produced:
>
> [IBM][iSeries Access ODBC Driver][DB2 UDB]SQL0122 - Column DIPODT or expression in Select list is not valid.
>
> Select OHBPO#, DIPOLN, DIPODT, ODPN, O8BTPN, EO6DES, ODORGQ, O6CRQM, O6CRQY, OHORDD, ODSHPD, SUM(ODSHPQ) AS SHIPQTY, CMCITY, ODCARR from ERMTST010.O4ER7 GROUP by OHBPO#, DIPOLN



Relevant Pages

  • Re: DELETING 100 million from a table weekly SQl SERVER 2000
    ... > The delete statement's where clause has the conditions for A, ... using a predicate that can be satisfied by the clustered index, ... > 1) Does this setting ROWCOUNT first sort the table and then delete? ... it just deletes the first N rows it finds that satisfy the ...
    (microsoft.public.sqlserver.tools)
  • RE: date time in WHERE clause
    ... > use in the WHERE clause of my SELECT statement. ... > So i'm guessing there's something wrong in my query syntax. ... > If I have a simple two column table with datetime and char data like this: ... but it's the equals I'm having trouble with. ...
    (microsoft.public.sqlserver.programming)
  • Number of 2SATs in 3SAT
    ... to put in X and be sure every clause in F ... to satisfy this clause. ... and the clause to variable ratio. ... I don't have a closed form formula for x, yet, ...
    (comp.theory)
  • Number of 2SATs in 3SAT
    ... to put in X and be sure every clause in F ... to satisfy this clause. ... and the clause to variable ratio. ... I don't have a closed form formula for x, yet, ...
    (sci.math)
  • Number of 2SATs in 3SAT
    ... to put in X and be sure every clause in F ... to satisfy this clause. ... and the clause to variable ratio. ... I don't have a closed form formula for x, yet, ...
    (sci.logic)