× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Try this (lines I added or changed are denoted by C++, change them back to C+). If it doesn't work
you may want to build and prepare your statement dynamically:

C/exec sql
C+ DECLARE R2CSR CURSOR FOR
C+
C++ WITH Temp as (
C+ SELECT MPMRS, CLSUPR, ROUND(AVG(NULLIF(A1,0)),0) AS A1,
C+ ROUND(AVG(NULLIF(A2,0)),0) AS A2, ROUND(AVG(NULLIF(A3,0)),0) AS A3,
C+ ROUND(AVG(NULLIF(A4,0)),0) As A4, ROUND(AVG(NULLIF(A5,0)),0) AS A5
C+
...
C+
C++ Group By mpMrs,CLSUPR )
C++
C++ Select * from Temp
C+ ORDER BY
C+ (Case When :WKSTARDSC = 'OVERALL AVERAGE' Then A1
C+ When :WKSTARDSC = 'i5 SCREEN TIME' Then A2
C+ When :WKSTARDSC = '# OF ACCOUNTS ATTEMPTED' Then A3
C+ When :WKSTARDSC = '# OF TOTAL INSTRUMENTS' Then A4
C+ When :WKSTARDSC = '# OF SCREENS COMPLETED' Then A5 End) DESC
C/end-exec

-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Jay Vaughn
Sent: Thursday, May 01, 2008 4:48 PM
To: RPG programming on the AS400 / iSeries
Subject: RE: SQL HELP

ok, changed the a1, a2, a3, a4, a5, to 3,4,5,6,7 and program compilese but
does not sort at all.

Thanks,

Jay Vaughn
Senior I5 Programmer/Analyst
RateWatch
(P) 251.209.8968
www.rate-watch.com


-----Original Message-----
From: "Jay Vaughn" <jayv@xxxxxxxxxxxxxx>
To: "RPG programming on the AS400 / iSeries" <rpg400-l@xxxxxxxxxxxx>
Date: Thu, 01 May 2008 15:45:32 -0500
Subject: RE: SQL HELP


duh... of course it is... nevermind! :D

Thanks,

Jay Vaughn
Senior I5 Programmer/Analyst
RateWatch
(P) 251.209.8968
www.rate-watch.com


-----Original Message-----
From: "Jay Vaughn" <jayv@xxxxxxxxxxxxxx>
To: "RPG programming on the AS400 / iSeries" <rpg400-l@xxxxxxxxxxxx>
Date: Thu, 01 May 2008 15:43:06 -0500
Subject: RE: SQL HELP


and a2 is 4 and so on?

Thanks,

Jay Vaughn
Senior I5 Programmer/Analyst
RateWatch
(P) 251.209.8968
www.rate-watch.com


-----Original Message-----
From: "Murphy, Mark" <MurphyM@xxxxxxxxxx>
To: "RPG programming on the AS400 / iSeries" <rpg400-l@xxxxxxxxxxxx>
Date: Thu, 1 May 2008 16:37:48 -0400
Subject: RE: SQL HELP


The suggestion was not to remove the A, but to tell it which result set
column number to sort on. For
example, A1 is column 3 in your SQL.

-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx]
On Behalf Of Jay Vaughn
Sent: Thursday, May 01, 2008 4:32 PM
To: RPG programming on the AS400 / iSeries
Subject: Re: SQL HELP

in the order clause, removing the "A" from a1, a2, a3, a4, and a5 allows
the program to compile but does not allow the sorting to occur like it
should when i run the pgm... so what else?

Thanks,

Jay Vaughn
Senior I5 Programmer/Analyst
RateWatch
(P) 251.209.8968
www.rate-watch.com


-----Original Message-----
From: rob@xxxxxxxxx
To: RPG programming on the AS400 / iSeries <rpg400-l@xxxxxxxxxxxx>
Date: Thu, 1 May 2008 16:09:12 -0400
Subject: Re: SQL HELP


Sorting by derived columns often necessitates a Common Table Expression or
CTE, or, change
C+ (Case When :WKSTARDSC = 'OVERALL AVERAGE' Then A1
to
C+ (Case When :WKSTARDSC = 'OVERALL AVERAGE' Then 3
And the 3 will be the third column in the selection. I prefer CTE's in
case someone adds a new selection field. Then it's more documenting then
positional.

If we trim this down to:
C/exec sql
C+ DECLARE R2CSR CURSOR FOR
C+
C+ SELECT MPMRS, CLSUPR, ROUND(AVG(NULLIF(A1,0)),0) AS A1,
C+ ROUND(AVG(NULLIF(A2,0)),0) AS A2, ROUND(AVG(NULLIF(A3,0)),0) AS A3,
C+ ROUND(AVG(NULLIF(A4,0)),0) As A4, ROUND(AVG(NULLIF(A5,0)),0) AS A5
C+
...
C+
C+ Group By mpMrs,CLSUPR
C+ ORDER BY
C+ (Case When :WKSTARDSC = 'OVERALL AVERAGE' Then A1
C+ When :WKSTARDSC = 'i5 SCREEN TIME' Then A2
C+ When :WKSTARDSC = '# OF ACCOUNTS ATTEMPTED' Then A3
C+ When :WKSTARDSC = '# OF TOTAL INSTRUMENTS' Then A4
C+ When :WKSTARDSC = '# OF SCREENS COMPLETED' Then A5 End) DESC
C/end-exec

Rob Berendt

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.