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



I use PREPAREs to sort subfiles, and I think they work pretty well --
they're not always lighting-fast, but they're fast enough (the users have
never complained), and they save a whole heck of a lot of programming. 
Building the proper indexes (if possible) always helps a lot.

As for building the statement, boy am I grateful for "Eval" ! :-) I don't
even want to think about trying to do it in RPGIII.  A couple of tricks I
use:

1) Define the field you're going to use to contruct your statement as
VARYING

2) Segment the process, maybe even using subroutines -- for example, a
subroutine to build the "SELECT" clause, another to build the "FROM"
clause, another for the "WHERE", etc.  Depending on the complexity of your
logic, you can combine two or more of these, but I find having distinct
chunks of code to look at makes debugging a whole lot easier.

3) When you have no idea what combination of things you're going to have
(e.g. the WHERE or ORDER BY clauses), add continuation pieces as you go
along and then strip out the last one, e.g.:

        Eval STMT='WHERE'                               << note: no trailing 
blank
        If      Condition1
        Eval    STMT = STMT + ' FLDA=:AVAL AND' << note leading blank before 
FLDA
        EndIf
        If      Condition2
        Eval    STMT = STMT + ' FLDB=:BVAL AND'
        EndIf
        <etc.>
        Eval    STMT=%SUBST(STMT,1,%LEN(%TRIM(STMT))-4)
(the last Eval strips off the final " AND")

4) When in doubt, put the program into debug and look at the statement
you've created. Then copy/paste it into interactive SQL and see what it
does -- you can find a lot of "gotchas" that way, along with testing
different options for performance.

hth

Midrange Systems Technical Discussion <midrange-l@xxxxxxxxxxxx> writes:
>If I were to use SQL, what is the most straightforward way to build the
>SQL string and run it? Would that be embedded SQL with a prepare? If so,
>I have no objection, or enlighten me of a better way?


Mike Naughton
Senior Programmer/Analyst
Judd Wire, Inc.
124 Turnpike Road
Turners Falls, MA  01376
413-863-4357 x444
mnaughton@xxxxxxxxxxxx


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.