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



So you are having troubles injecting ' and alblst in (' + quotedlistofvalues +') ' into your SQL dynamically built statement? I have sometimes built a temp table or a real template table then build it in QTEMP, load the selections and used it in a sub select or join. Other times I have just built my list of values for the in clause, this typically requires a loop structure of some kind building the list properly.

-Matt

-----Original Message-----
From: RPG400-L [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Fry, Kim
Sent: Tuesday, December 11, 2018 2:13 PM
To: rpg400-l@xxxxxxxxxxxx
Subject: RE: Ability to see Embedded SQL Select Statement

Maybe this might help with what I'm trying to accomplish and why I'm trying to see how the SQL statement is being created.

The SQL is dynamically created using variables passed into the program. We now want to include dwelling types which can accomplish with the IN statement. But the dwelling types being passed into the program are variable depending on the information needed for the selection.

I can make the SQL work just fine if I "hardcode" the line as such: alblst in('R',T') But where I'm running into the formatting issues is when I need to create the IN statement using the variables passed into the program and using the TRIM command.

When I try to use the variable along with the trim, I'm not getting the results I need for the query.

I hope that the above information make sense.







-----Original Message-----
From: RPG400-L [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Dexter Thompson
Sent: Tuesday, December 11, 2018 3:21 PM
To: rpg400-l@xxxxxxxxxxxx
Subject: Re: Ability to see Embedded SQL Select Statement

Here's is what I do. At the beginning of the program I create a table in QTEMP

exec sql
drop table qtemp/MySQL cascade ; // in case still there from a previous run
exec sql
Create Table Qtemp/MySQL
(mysql_cmd char (5000) with default ' ') ;

Then when I build my statement in a work field for the Declare and Prepare statements

Mysqlstmt = 'Select x, y, z from table1...... '

I then insert the field into my temp table.

exec sql
insert into qtemp/mysql (mysql_cmd)
values(:Mysqlstmtt ) ;

Now I have the exact statement built. The second advantage is you can copy the statement from the qtemp file and execute it in ACS, WinSQL, etc to see where it is failing.

Good luck.

On Tue, Dec 11, 2018 at 2:54 PM Tyler, Matt <matt.tyler@xxxxxxxxxxxxxx>
wrote:

You can start a DB monitor (best if done via Run SQL Scripts or the
performance center in ACS ), run the program and the inspect the DB
monitor. The executed statement should appear if you set up the DB
monitor properly.

-Matt

-----Original Message-----
From: RPG400-L [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of
Alan Campin
Sent: Tuesday, December 11, 2018 12:51 PM
To: RPG programming on the IBM i / System i <rpg400-l@xxxxxxxxxxxx>
Subject: Re: Ability to see Embedded SQL Select Statement

Basically no. The declare statement is only an instruction to the compiler.
It does not generate executable code. If you look at the RPG view in
the debugger you will see the code that is actually being executed.


On Tue, Dec 11, 2018 at 11:47 AM Fry, Kim <kfry@xxxxxxxxxx> wrote:

Hi everyone,

The program that I currently updating contains the following SQL
statement.

exec sql
DECLARE housesBefore CURSOR for
SELECT ALAJNB,
ALBHNB,
ALBFCD,
ALBGCD,
ALBKCD,
ALBLTX,
ALBMTX,
ALBNTX
FROM homrtv01
WHERE ((upper(ALBFCD) < :@AddrLoc) or
(upper(ALBFCD) = :@AddrLoc and
upper(ALBGCD) < :@Fraction) or
(upper(ALBFCD) = :@AddrLoc and
upper(ALBGCD) = :@Fraction and
upper(ALBKCD) <= :@Apartment)) and
upper(ALBHCD) = :@PreDirect and
upper(ALBITX) like '%' || trim(:@StrWord1) || '%' and
upper(ALBITX) like '%' || trim(:@StrWord2) || '%' and
upper(ALBITX) like '%' || trim(:@StrWord3) || '%' and
upper(ALBITX) like '%' || trim(:@StrWord4) || '%' and
upper(ALBITX) like '%' || trim(:@StrWord5) || '%' and
upper(ALBJTX) = :@City and
upper(ALBICD) = :@State and
ALBTST = ' '
ORDER BY upper(ALBFCD) desc,
upper(ALBGCD) desc,
upper(ALBKCD) desc;


exec sql open housesBefore;

dou sqlstt <> '00000';

exec sql
fetch housesBefore into :houseData;

if sqlstt = '00000';


The SQL statement works correctly, but I need to add additional
selection criteria information into it but I've been encountering
issues with the formatting of the select statement and was wondering
if there is a way through debug to see the actual SQL statement that
is being created so that I can determine where the formatting
problem is
so that I can fix it.

I'm using STRDBG command to view the variables in the program.


I've worked on SQLRPGLE programs where I've build the select
statement from scratch and then declared it to a cursor. For example:
Prepare sel from :selectStmt
Declare c1 cursor for sel


With this method I was able to debug my SQL statement that was built
by using the EVAL on the selectStmt variable.

Any help on how to display the select statement that is being built
without having to update the current program to move the select
builds into a variable would be appreciated.

Thank you

_____
Kimberly Fry


--
This is the RPG programming on the IBM i (AS/400 and iSeries)
(RPG400-L) mailing list To post a message email:
RPG400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list
options,
visit:
https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.midrange.
co
m_mailman_listinfo_rpg400-2Dl&d=DwICAg&c=2S-2xx8Cum_thMfWs-kOOHQTwol
Pv
SZ4PFLhr1wDDGs&r=wgq2KO1Tl8HswJht2RKpmz7qvL2YDU_M-VhnRH6r43I&m=nF4xh
9L
aPAffkNhxK79YQ2SWnU_dkdD2Zwocill7HPE&s=Dh38sRzpyJM5w40Qgv6MUR7PhQesA
aA ma3Rjqgwpk2E&e= or email: RPG400-L-request@xxxxxxxxxxxx Before
posting, please take a moment to review the archives at

https://urldefense.proofpoint.com/v2/url?u=https-3A__archive.midrange.
com_rpg400-2Dl&d=DwICAg&c=2S-2xx8Cum_thMfWs-kOOHQTwolPvSZ4PFLhr1wDDGs&
r=wgq2KO1Tl8HswJht2RKpmz7qvL2YDU_M-VhnRH6r43I&m=nF4xh9LaPAffkNhxK79YQ2
SWnU_dkdD2Zwocill7HPE&s=xRnaGYqdepCfAA2Dlz0UnZ5QuAhne9Ax5GgqOrT4a7Q&e=
.

Please contact support@xxxxxxxxxxxx for any subscription related
questions.

Help support midrange.com by shopping at amazon.com with our
affiliate
link:
https://urldefense.proofpoint.com/v2/url?u=https-3A__amazon.midrange
.c
om&d=DwICAg&c=2S-2xx8Cum_thMfWs-kOOHQTwolPvSZ4PFLhr1wDDGs&r=wgq2KO1T
l8
HswJht2RKpmz7qvL2YDU_M-VhnRH6r43I&m=nF4xh9LaPAffkNhxK79YQ2SWnU_dkdD2
Zw ocill7HPE&s=QLXqhYWPoPPMBHUkoAk5kD796-o9XiwK2Udab1vtL10&e=

--
This is the RPG programming on the IBM i (AS/400 and iSeries)
(RPG400-L) mailing list To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit:
https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.midrange.co
m_mailman_listinfo_rpg400-2Dl&d=DwICAg&c=2S-2xx8Cum_thMfWs-kOOHQTwolPv
SZ4PFLhr1wDDGs&r=wgq2KO1Tl8HswJht2RKpmz7qvL2YDU_M-VhnRH6r43I&m=nF4xh9L
aPAffkNhxK79YQ2SWnU_dkdD2Zwocill7HPE&s=Dh38sRzpyJM5w40Qgv6MUR7PhQesAaA
ma3Rjqgwpk2E&e= or email: RPG400-L-request@xxxxxxxxxxxx Before
posting, please take a moment to review the archives at
https://urldefense.proofpoint.com/v2/url?u=https-3A__archive.midrange.
com_rpg400-2Dl&d=DwICAg&c=2S-2xx8Cum_thMfWs-kOOHQTwolPvSZ4PFLhr1wDDGs&
r=wgq2KO1Tl8HswJht2RKpmz7qvL2YDU_M-VhnRH6r43I&m=nF4xh9LaPAffkNhxK79YQ2
SWnU_dkdD2Zwocill7HPE&s=xRnaGYqdepCfAA2Dlz0UnZ5QuAhne9Ax5GgqOrT4a7Q&e=
.

Please contact support@xxxxxxxxxxxx for any subscription related
questions.

Help support midrange.com by shopping at amazon.com with our affiliate
link:
https://urldefense.proofpoint.com/v2/url?u=https-3A__amazon.midrange.c
om&d=DwICAg&c=2S-2xx8Cum_thMfWs-kOOHQTwolPvSZ4PFLhr1wDDGs&r=wgq2KO1Tl8
HswJht2RKpmz7qvL2YDU_M-VhnRH6r43I&m=nF4xh9LaPAffkNhxK79YQ2SWnU_dkdD2Zw
ocill7HPE&s=QLXqhYWPoPPMBHUkoAk5kD796-o9XiwK2Udab1vtL10&e=
--
This is the RPG programming on the IBM i (AS/400 and iSeries)
(RPG400-L) mailing list To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit:
https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.midrange.co
m_mailman_listinfo_rpg400-2Dl&d=DwIGaQ&c=2S-2xx8Cum_thMfWs-kOOHQTwolPv
SZ4PFLhr1wDDGs&r=wgq2KO1Tl8HswJht2RKpmz7qvL2YDU_M-VhnRH6r43I&m=xpSQ5C2
IdbV7D0E8o2WsFrrNz5yyPolPbX8yx06vl60&s=byzZu3G_OzGag4glrQeygSaVjdupsq5
eQ3taMp5H3Qw&e= or email: RPG400-L-request@xxxxxxxxxxxx Before
posting, please take a moment to review the archives at
https://urldefense.proofpoint.com/v2/url?u=https-3A__archive.midrange.com_rpg400-2Dl&d=DwIGaQ&c=2S-2xx8Cum_thMfWs-kOOHQTwolPvSZ4PFLhr1wDDGs&r=wgq2KO1Tl8HswJht2RKpmz7qvL2YDU_M-VhnRH6r43I&m=xpSQ5C2IdbV7D0E8o2WsFrrNz5yyPolPbX8yx06vl60&s=U7fdpvZqRpDeKrwLUppo2HXnOWG-ylYPrSjhkzzi4Jc&e=.

Please contact support@xxxxxxxxxxxx for any subscription related
questions.

Help support midrange.com by shopping at amazon.com with our affiliate
link:
https://urldefense.proofpoint.com/v2/url?u=https-3A__amazon.midrange.c
om&d=DwIGaQ&c=2S-2xx8Cum_thMfWs-kOOHQTwolPvSZ4PFLhr1wDDGs&r=wgq2KO1Tl8
HswJht2RKpmz7qvL2YDU_M-VhnRH6r43I&m=xpSQ5C2IdbV7D0E8o2WsFrrNz5yyPolPbX
8yx06vl60&s=dM3JIDWFM4PTlaNX763mUiguw1W9D2tVPiEoZOipPKU&e=




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.