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



<snip>
I am trying desperately to get this embedded sql down and thought I had
it 
after the last go around, unfortunately I must be 1. dumber than I
thought, 
2. losing my mind or 3. had too much gaterade today.  In any event, I am

using the following code to extract the records from the logical file:
</snip>

Not qualified to discuss options 1-3, but...

You need to specify the same fields for Order By and Group By...SQL is
VERY fussy about that.  If you need to present the information in a
different sequence, you could use a with clause:

C     BLDSQL        BEGSR                                        
C/EXEC SQL                                                       
C+    DECLARE SQLCURSOR CURSOR                                   
C+    FOR 
C+    with temptbl 
C+   (ilnsoldto,icmname, sumprice, sumuavcst, margin, mpct)
C+    as  (SELECT                                                 
C+    ILNSOLDTO,                                                 
C+    ICMNAME,                                                   
C+    SUM(ILNEPRICE) as sumprice,
C+    SUM(ILNEUAVCST) as sumuavcst,
C+    SUM(ILNEPRICE) - SUM(ILNEUAVCST) AS MARGIN,                
C+    (SUM(ILNEPRICE) - SUM(ILNEUAVCST)) / SUM(ILNEPRICE) AS MPCT
C+    FROM SPECGASLF                                             
C+    WHERE                            
C+          ILNINVDATE > :STARTDATE AND
C+          ILNINVDATE <= :ENDDATE     
C+    GROUP BY                         
C+             ILNSOLDTO,              
C+             ICMNAME                 
C+    ORDER BY                         
C+             ILNSOLDTO,              
C+             ICMNAME )
C+
C+    SELECT                                                 
C+    ILNSOLDTO,                                                 
C+    ICMNAME,                                                   
C+    sumprice,
C+    sumuavcst,
C+    MARGIN,                
C+    MPCT
C+    FROM temptbl
C+    ORDER BY                         
C+             MPCT DESC               
C/END-EXEC                             

You could also do your original select (with the Order By changed) and
save the values in an array, work file, user index (your choice) and
retrieve values in the sequence of your choice.

Hope that helps,
--Bruce Guetzkow


As an Amazon Associate we earn from qualifying purchases.

This thread ...


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.