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



Steve,

A fourth option:

If your list of values is too long to enumerate with host variables or the list can vary in size insert your list into a temporary table with one row for each parameter. Check for column3 using an EXISTS or IN predicate using the temporary table in a prepared SQL statement.

Paul Morgan

Principal Programmer Analyst
IT Supply Chain/Replenishment

-----Original Message-----
From: midrange-l-bounces@xxxxxxxxxxxx [mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of Needles,Stephen J
Sent: Thursday, June 21, 2012 3:20 PM
To: Midrange Systems Technical Discussion
Subject: RE: Embedded SQL using IN and a host variable

Thanks Birgitta!

I was afraid of this.

Steve

-----Original Message-----
From: midrange-l-bounces@xxxxxxxxxxxx [mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of Birgitta Hauser
Sent: Thursday, June 21, 2012 2:16 PM
To: 'Midrange Systems Technical Discussion'
Subject: AW: Embedded SQL using IN and a host variable

Hi,

You can't do it in this way!

There are 3 options:
1. pass a host variable for each parameter specified in the IN predicate
2. use dynamic SQL
3. Try something strange like this:

/Free
//Build your string containing all elements separated by a comma
Path = 'Data1' + ', ' + 'Data2' + ', '+ ...;

Exec SQL
Declare get cursor with return to client for
SELECT distinct Column1, Column2, Column3
FROM Table
WHERE :Path like '%' concat Trim(Column3) concat ', ' concat
'%';
... etc

I didn't try it, but it should work and I'm not sure about the performance.

Mit freundlichen Grüßen / Best regards

Birgitta Hauser

"Shoot for the moon, even if you miss, you'll land among the stars." (Les
Brown)
"If you think education is expensive, try ignorance." (Derek Bok)
"What is worse than training your staff and losing them? Not training them
and keeping them!"

-----Ursprüngliche Nachricht-----
Von: midrange-l-bounces@xxxxxxxxxxxx
[mailto:midrange-l-bounces@xxxxxxxxxxxx] Im Auftrag von Needles,Stephen J
Gesendet: Thursday, 21.6 2012 20:33
An: midrange-l@xxxxxxxxxxxx
Betreff: Embedded SQL using IN and a host variable

I have a need to accept a list of values that needs to be compared to a
column in a table using an embedded SQL statement in RPGLE.

The list:

'data1'
'data2'

This list is assembled so that path looks like:

'data1','data2'

When used in the SQL statement...

Select stuff from table where column3 in (:path);

I end up with an SQLCod = 100.

Running the SQL outside of the program produces the needed data.

Select * from table where column3 in ('data1','data2');

Is there a solution short of repeating the condition over and over again?
Using STRIP and TRIM with the host variable had no impact.

Stub of Code below:

dpath s 9999

dcolumn1 s 5
dcolumn2 s 3
dcolumn3 s 9999

/free
eval path = '''';
eval path = %trim(path) +
'data1' + '''';

eval path = %trim(path) + ',' + '''' +
'data2' + '''';

exec sql
declare get cursor with return to client for
SELECT distinct
Column1, Column2, Column3 FROM Table WHERE
Column3 in (:path);

exec sql open get;

exec sql fetch get into :Column1, :Column2, :Column3;

if sqlcod = sqlcod;
eval sqlcod = sqlcod;
endif;

/end-free



============================================================================
==
This communication, including attachments, is confidential, may be subject
to legal privileges, and is intended for the sole use of the addressee. Any
use, duplication, disclosure or dissemination of this communication, other
than by the addressee, is prohibited. If you have received this
communication in error, please notify the sender immediately and delete or
destroy this communication and all copies.
--
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.