|
Here is what i usually do : Declare CreateSQLSTMT Prepare Fetch the create do this : D Qt C '''' D SqlStmt S 2512 D SqlSltCpt S 4s 0 D Type S 1 D Status S 1 D SqlFld C 'F1.thlib, - D F1.thfile, - D F1.thuser, - D F1.thpgm , - D F1.thevent, - D date(F1.thtime) - D as key1, - D time(F1.thtime) - D as key2, - D rrn(f1)' * D SQLFrom1 C 'Trighisp1 as F1' D SQLFrom2 C 'Trigdifp1 as F1' c Eval SqlSltCpt = 0 c Eval SqlStmt='SELECT ' * * Zones ........................................................... c Eval SqlStmt=%trim(SqlStmt) c +' ' c +SqlFld c * * Fichiers ........................................................ c Eval SqlStmt=%trim(SqlStmt) c +' FROM ' c + SQLFrom * * Sélection ....................................................... c If ££Lib<>' ' c Exsr SqlFirst c Eval SqlStmt=%trim(SqlStmt) c + ' F1.Thlib = ' c + Qt + %trim(££Lib) + Qt c Endif * c If ££File<>' ' c Exsr SqlFirst c Eval SqlStmt=%trim(SqlStmt) c + ' F1.Thfile = ' c + Qt + %trim(££File) +Qt c Endif And so on.... NB : SQLfirst is there to add the AND after the first slect clause. Hope this help ----- Original Message ----- From: <Michael_Schutte@xxxxxxxxxxxx> To: "RPG programming on the AS400 / iSeries" <rpg400-l@xxxxxxxxxxxx> Sent: Wednesday, April 19, 2006 2:32 PM Subject: Re: EMBEDDED SQL: Optional values in where clause? C/EXEC SQL C+ DECLARE C1 DYNAMIC SCROLL CURSOR FOR C+ SELECT PRFNM,PRLNM,PREN,PRTEDH,PRPLNM,PRCLN C+ FROM FILE C+ WHERE PRER = :A1ER C+ AND (PRL01 = :A1L01 Or :A1L01 = ' ') C+ AND (PRL02 = :A1L02 Or :A1L02 = ' ') C+ AND (PRL03 = :A1L03 Or :A1L03 = ' ') C+ AND (PRL04 = :A1L04 Or :A1L04 = ' ') C+ AND (PRSEX = :A1SEX Or :A1SEX = ' ') C+ AND (PRSTA1 = :A1STA Or :A1STA = ' ') C+ AND (SUBSTRING(PREN,6,4) = :A1EN4 Or :A1EN4 = ' ') C+ AND (PRFNM LIKE C+ (CASE C+ WHEN :FName <> ' ' THEN :FName C+ ELSE '#$%¢#%¢#$%¢#$¢#$%¢' C+ END) C+ OR :FName = ' ') C+ AND ((PRLNM LIKE C+ (CASE C+ WHEN :LName <> ' ' THEN :LName C+ ELSE '#$%¢#%¢#$%¢#$¢#$%¢' C+ END) C+ OR :LName = ' ') C+ OR (PRPLNM LIKE C+ (CASE C+ WHEN :LName <> ' ' And :A1PLNmYN = 'Y' THEN :LName C+ ELSE '#$%¢#%¢#$%¢#$¢#$%¢' C+ END) C+ OR (:LName = ' ' And :A1PLNMYN = 'Y'))) C/END-EXEC This SQL statement will select record from the file only when the condition between the parenthesis results in true. There are several host variables that can be blank, if they are blank then I want that record to be return. Anyway, I think you'll be able to figure this out. Just ask if you need help. Michael Schutte Work 614-492-7419 email michael_schutte@xxxxxxxxxxxx "Thomas Gard" <thomas.gard@gmai l.com> To Sent by: rpg400-l@xxxxxxxxxxxx rpg400-l-bounces@ cc midrange.com Subject EMBEDDED SQL: Optional values in 04/18/2006 08:16 where clause? PM Please respond to RPG programming on the AS400 / iSeries <rpg400-l@midrang e.com> I believe recently I saw a thread here or somewhere on how to deal with optional predicates in a where clause, i.e. sometime parms will be passed in to be used in where clause, sometime not, its possible to set the where clause to function accordingly on what is passed in. I cant recall where I saw it and did not bookmark it, can anyone point me to the thread or highlight how to do that, thanks. -- This is the RPG programming on the AS400 / iSeries (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.
As an Amazon Associate we earn from qualifying purchases.
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.