The between on the client number is probably killing you. You previously stated that if client isn't entered, then you are doing a range between 0 and 99999999. Since you are building the sql string dynamically, why even bother putting it in the sql statement?
wSql = 'SELECT * FROM MY FILE +
WHERE DATE BETWEEN ? AND ?' ;
If wClientN <> <> 0;
wSQL += ' AND CLIENT = ' + wClientN;
EndIf;
wSql += ' AND AMOUNT BETWEEN ? AND ?';
Exec SQL
Prepare S1 from :wSQL;
If wClientN <> 0;
Exec SQL
Declare c1 cursor for s1 using (:wdate1, :wdate2, :wClientN, :wAmount1, :wAmount2)
Else;
Exec sql
Declare c2 cursor for s1 using (:wdate1, :wdate2, :wAmount1, :wAmount2)
EndIf;
Or if you want to declare just one cursor, you can do what I previously suggested.
wSql = 'SELECT * FROM MY FILE +
WHERE DATE BETWEEN ? AND ?
AND ? in (0,CLIENT) +
AND AMOUNT BETWEEN ? AND ?';
Exec SQL
Prepare S1 from :wSQL;
Exec SQL
Declare c1 cursor for s1 using (:wdate1, :wdate2, :wClientN, :wAmount1, :wAmount2)
-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of David FOXWELL
Sent: Monday, March 07, 2011 10:47 AM
To: RPG programming on the IBM i / System i
Subject: RE: Embedded sql without index faster than with index
-----Message d'origine-----
[mailto:rpg400-l-bounces@xxxxxxxxxxxx] De la part de Schutte,
Michael D
What happens if you code it like so.
Select fields from files where :inputclientNbr in (0,
clientNumber) and :inputAmt in (0, amount)
When inputClientNbr host variable is 0, then all clients
would end up getting selected, otherwise only the
inputclientnumber is selected.
When inputAmt is 0, then all transaction amounts will be
selected, otherwise only that transaction amount would be.
User can enter one client number, an upper and a lower amount and a start and end date, hence I used between.
I'm building my cursor like this :
wSql =
'SELECT * FROM MYFILE +
WHERE +
DATE BETWEEN ''' + wDate1 + ''' AND +
''' + wDate2 + ''' AND +
CLIENT BETWEEN ' + wClientN1 + ' AND +
' + wClientN2 + ' AND +
AMOUNT BETWEEN ' + wAmount1 + ' AND +
' + wAmount2 + ';
EXEC SQL
PREPARE S1 FROM : wSql;
How would the syntax be if I used host variables?
--
This is the RPG programming on the IBM i / System i (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit:
http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at
http://archive.midrange.com/rpg400-l.
________________________________
Notice from Bob Evans Farms, Inc: This e-mail message, including any attachments, may contain confidential information that is intended only for the person or entity to which it is addressed. Any unauthorized review, use, disclosure or distribution is strictly prohibited. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message and any attachments.
As an Amazon Associate we earn from qualifying purchases.