Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Using IN with this query?

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
ramsri

Active User


Joined: 18 Oct 2008
Posts: 380
Location: India

PostPosted: Wed Feb 18, 2009 7:40 pm    Post subject: Using IN with this query?
Reply with quote

Hi,

I have written below query in SPUFI to fetch details from a table in our DB successfully.

Code:

SELECT * FROM DM01.ORDER                           
 WHERE (ORD_KEY,ORD_NBR) = ('X42','    XXXX42')
    OR (ORD_KEY,ORD_NBR) = ('X43','    XXXX43')
WITH UR;                                                   


I would like to know how to use IN instead of writing it separately?

Thanks.
Back to top
View user's profile Send private message

Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1224
Location: Israel

PostPosted: Wed Feb 18, 2009 8:36 pm    Post subject:
Reply with quote

In this case, you can't use IN
If you had:
Code:
WHERE (ORD_KEY,ORD_NBR) = ('X42','    XXXX42')
   OR (ORD_KEY,ORD_NBR) = ('X42','    XXXX43')
then you could use
Code:
WHERE ORD_KEY = 'X42' AND ORD_NBR IN ('    XXXX42','    XXXX43')
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Wed Feb 18, 2009 10:03 pm    Post subject:
Reply with quote

Your where clause can be broken down as

Code:


WHERE

(ORD_KEY = 'X42' AND ORD_NBR = '    XXXX42' )

OR

(ORD_KEY = 'X43' AND ORD_NBR = '    XXXX43' )



cannot use IN clause here ...
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1224
Location: Israel

PostPosted: Thu Feb 19, 2009 3:38 pm    Post subject: Reply to: Using IN with this query?
Reply with quote

In fact, I tried:
Code:
WHERE (ORD_KEY,ORD_NBR) IN ( ('X42','    XXXX42') , ('X43','    XXXX43') )
but couldn't make it work.
SQLCODE -216 that I received when playing with the values leads me to think that something like that may be possible.
Back to top
View user's profile Send private message
ramsri

Active User


Joined: 18 Oct 2008
Posts: 380
Location: India

PostPosted: Thu Feb 19, 2009 4:31 pm    Post subject: Reply to: Using IN with this query?
Reply with quote

Guys, thanks for all your replies.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Join in SQL Query vickey_dw DB2 2 Tue Jan 17, 2017 12:15 am
This topic is locked: you cannot edit posts or make replies. MQ setup query mohitsaini Java & MQSeries 4 Sun Jan 08, 2017 1:53 am
No new posts DB2 query Using Recursion, Converting... smilewithashu2 DB2 1 Tue Jan 03, 2017 12:50 pm
No new posts SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am
This topic is locked: you cannot edit posts or make replies. Db2 SQL query to convert rows into co... subratarec DB2 5 Thu Nov 17, 2016 4:51 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us