1) Dynamic SQL
2) list each element (you can use host variables for elements in the list)
3) create an array to be used for the IN clause. Make the array fit your
max elements in the list. Use the array in your static SQL, listing all
elements in the IN clause. For the case where you don't have enough real
elements to fill the array, just repeat the last element till your reach the
max.
Elvis
RPG & DB2 Summit | Minneapolis | October 1-4
Mike Cain - DB2 for i5/OS Temporary Indexes - The Good, The Bad, The Ugly
October 16
2007 System i Fall Technical Conference | Orlando | November 4-7
Celebrating 10-Years of SQL Performance Excellence on IBM System i, eServer
iSeries and the server affectionately known as the AS/400
-----Original Message-----
From: midrange-l-bounces@xxxxxxxxxxxx
[mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of AGlauser@xxxxxxxxxxxx
Sent: Thursday, September 13, 2007 3:57 PM
To: Midrange technical discussions
Subject: Quick (I hope) embedded SQL question - using IN()
I've searched the list archives and Google but can't get the right terms
to find a discussion of this. I haven't read all of the relevant Redbooks
yet, so I apologize if this is an RTFM question, but it would be really
handy to get this particular query going soon. I'm using RPG, but I think
this applies to COBOL and SQL CLI as well.
There was a related thread on the RPG400 list a day or two ago about how
to view the most recent SQL statement. Charles Wilt suggested using the
'Display last SQL statement' option from iSeries Navigator for the job,
but this just tells me that the job ran "OPEN {cursorName}". Doh!
This is my code so far:
list = '(''A'',''B'')';
exec sql DECLARE test CURSOR FOR
select field1, field2, field3
from testtbl
where field1 IN :list
FOR READ ONLY;
and testtbl contains
Field1 Field2 Field3
A 1 1
B 2 2
A 2 2
C 3 3
When I FETCH from the 'test' cursor, I get SQLSTATE = 02000, no rows
returned. However if I run the query from iSeries Navigator, I get the
result I'd expect:
Field1 Field2 Field3
A 1 1
B 2 2
A 2 2
I expect that the SQL engine is seeing one comparison value of "('A','B')"
instead of two, "A" and "B". Do I need to use dynamic SQL (that is
PREPARE) here, or do I just need to mess with the syntax some more?
- Adam
Attention:
The information contained in this message and or attachments is
intended only for the person or entity to which it is addressed and may
contain
confidential and/or privileged material. Any review, retransmission,
dissemination or other use of, or taking of any action in reliance upon,
this
information by persons or entities other than the intended recipient is
prohibited. If you received this message in error, please contact the sender
and
delete the material from any system and destroy any copies. Thank you for
your
time and consideration.
Attention:
Le contenu de ce message et(ou) les fichiers ci-joints s?adressent
exclusivement à la personne ou -entité à laquelle ils sont destinés. Ils
peuvent
contenir de l?information confidentielle, protégée et(ou) classifiée. Il est
strictement interdit à toute personne ou entité autre que le(la)
destinataire
prévu(e) de ce message d?examiner, de réviser, de retransmettre ou de
diffuser
cette information, de prendre une quelconque action en fonction ou sur la
base
de celle-ci, ou d?en faire tout autre usage. Si vous avez reçu ce message
par
erreur, veuillez communiquer avec l?expéditeur(trice), supprimer ce message
et
les fichiers ci-inclus de tout système, et en détruire toutes copies,
qu?elles
soient électroniques ou imprimées. Nous vous remercions de votre entière
collaboration.
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.