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: 1232
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: 1232
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 Need DB2 query to fetch previous row ! Chandan1993 DB2 10 Sat Jun 03, 2017 10:43 am
No new posts JCL to Set Return code based on DB2 S... vinu78 DB2 17 Mon Mar 13, 2017 9:47 pm
No new posts SQL query not working in Cobol program. CuriousMainframer COBOL Programming 14 Wed Feb 22, 2017 5:56 pm
No new posts Omegamon for DB2 query ashek15 DB2 0 Wed Feb 15, 2017 11:25 am
No new posts Query on DB2 WLM stored procedures ashek15 DB2 8 Sun Feb 12, 2017 11:13 pm


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