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



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

Follow-Ups:
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.