× 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 am not as expert on this as I would like, so I use several simple SQL statements when sometimes more complex might do the task. I am currently in V5R1 but learned embedded SQL in V4 something, maybe even V3.

I not know performance, virtually all my embedded SQL runs in some program in JOBQ anyway.

I have some embedded SQL statement to actually get the data, usually using a CURSOR which is like a step in a loop, I use the same statement outside of the loop, typically at very beginning or end, in which instead of actually getting the raw data, the statement is going after MIN(*) MAX(*) range or COUNT(*) instances of whatever the loop going after.

This may not be quite what you looking for, but here's example of me using COUNT in an embedded SQL. This is from a program that "inventories" scale of "problems" me "computer janitor" needs to address.

   *
  C/EXEC SQL
  C+ SELECT COUNT(*) INTO :CNTSQL
  C+ FROM ITH WHERE TPROD
  C+ NOT IN (SELECT IPROD FROM IIM)
  C/END-EXEC
   *
This counts how many inventory history records exist on items that no longer exist in the item master

You can manipulate the data as it comes in ...
Here's where we add two fields together as they come into RPG from SQL

  C/EXEC SQL
  C+ SELECT (FOD.ORUN+FOD.OMAC) INTO :W7CAL FROM FOD WHERE
  C+ FOD.ODID='OD' AND FOD.OORD=:W7ORD AND FOD.OOPNO=:W7OPNO
  C/END-EXEC

here's from something else we used to do, before we changed a formula. Notice the FOD.OOPER*6 where we doing math on the incoming value

 C*EXEC SQL
 C* SELECT (FOD.OOPER*6) INTO :W7CAL1 FROM FOD WHERE FOD.ODID='OD'
 C* AND FOD.OORD=:W7ORD AND FOD.OOPNO=:W7OPNO
 C*END-EXEC

Defining a cursor can get as complicated as doing CL OPNQRYF
Notice that each row here is actually selected columns from a combination of files.

 C/EXEC SQL
 C+ DECLARE C1 CURSOR FOR SELECT
 C+ SORD,SQREQ,SOFAC,IPROD,IDESC,IFII,IITYP,ICLAS,OOPNO,OWRKC,OOPDS
 C+ OOL,OOPER,OSTAT,SORTEM,OCDTE
 C+ FROM FSO,IIM,FRT,FOD WHERE SID='SO' AND IID='IM' AND
 C+ RID='RT' AND ODID IN('OD','RD') AND SPROD=IPROD AND SPROD=RPROD
 C+ AND SORD=OORD AND ROPNO=OOPNO AND OSTAT IN('1','3')
 C+ GROUP BY
 C+ SORD,SQREQ,SOFAC,IPROD,IDESC,IFII,IITYP,ICLAS,OOPNO,OWRKC,OOPDS
 C+ OOL,OOPER,OSTAT,SORTEM,OCDTE
 C+ ORDER BY SORD,OOPNO,OSTAT
 C/END-EXEC
  *

Adam Glauser wrote:
> >My question is this: is there a way to determine the number
> >of rows selected?

Al Mac wrote:
> In embedded SQL, and other SQL/400 for that matter, you can get a
>
> COUNT(*) of some record selection
> which tells you HOW MANY records (rows)
> were involved in whatever you were doing.

Al -
Am I correct that you mean I would first do my "SELECT field1, field2"
query, then do a "SELECT COUNT(*)" query with the same WHERE/GROUP BY/
HAVING?  I was hoping there would be some sort of count in the data
structures returned by the DBMS.  Is there significant processing involved
with doing the COUNT(*) query, or does the DBMS somehow cache the results
from the initial SELECT?

Thanks for the tip,
Adam


#####################################################################################
Attention:
The above message and/or attachment(s) is private and confidential and is intended only for the people for which it is addressed. If you are not named in the address fields, ignore the contents and delete all the material. Thank you. Have a nice day.

For more information on email virus scanning, security and content
management, please contact administrator@xxxxxxxxxxxx
#####################################################################################
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.



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.