IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

To search DB2 table based on Conditions in WHERE clause


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Chidane

New User


Joined: 25 Nov 2021
Posts: 11
Location: India

PostPosted: Thu Mar 16, 2023 9:00 am
Reply with quote

Hi Team,

Could you please help me in the requirement

The COMPTBL table has 2 fields - CompName, ID
The IDTABLE table has also some fields - ID, ReqtNo, Code
In the WHERE clause, I would like to search B.CODE = 'X', if the value of ReqtNo is 'ABC' else search B.CODE = 'Y' for all other values of ReqtNo column

Code:
SELECT COMPNAME FROM COMPTBL A , IDTABLE B
 WHERE  A.ID = B.ID
     AND B.CODE = 'X'  (search for this value only if B.REQTNO = 'ABC')
              otherwise check for B.CODE = 'Y' (for B.REQTNO <> 'ABC')

Appreciate your help.

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

Senior Member


Joined: 29 Apr 2008
Posts: 2017
Location: USA

PostPosted: Thu Mar 16, 2023 5:42 pm
Reply with quote

I would recommend first to RTFM, and next to post the questions. NOT VICE VERSA.

Code:
AND B.CODE = DECODE( B.REQTNO, 'ABC', 'X', 'Y' )
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Load new table with Old unload - DB2 DB2 6
No new posts Search two or more word with FILEAID Compuware & Other Tools 15
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
No new posts Pulling a fixed number of records fro... DB2 2
No new posts How to load to DB2 with column level ... DB2 6
Search our Forums:

Back to Top