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
 

 

Need to find the column name.

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

New User


Joined: 11 Oct 2008
Posts: 74
Location: Chicago, IL

PostPosted: Thu Jan 20, 2011 5:08 pm    Post subject: Need to find the column name.
Reply with quote

Hello,
I am running the following query

Select *
From Tab1
Where
Col1="XYZ" And
(Col2 like :ws-find or
Col3 like :ws-find or
Col4 like :ws-find or
Col5 like :ws-find or
Col6 like :ws-find or
Col7 like :ws-find)

I need to find the column name from which condition it is picking the data..
That is like which column is having ws-find.
COL2/COL3/COL4/COL5/COL6/COL7.

Also the length of ws-find is not fixed.
Its PIC X(10) but data may be of 3/4/5... character.

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

Kjeld

Active User


Joined: 15 Dec 2009
Posts: 365
Location: Denmark

PostPosted: Thu Jan 20, 2011 8:25 pm    Post subject:
Reply with quote

I am thinking of something like this (not tested, just an idea):
Code:

SELECT 'COL2',COL1,COL2,.. COLn
FROM TAB1
WHERE COL1 = 'XYZ' AND COL2 LIKE :WS-FIND
UNION
SELECT 'COL3',COL1,COL2,.. COLn
FROM TAB1
WHERE COL1 = 'XYZ' AND COL3 LIKE :WS-FIND
.
.
UNION
SELECT 'COL7',COL1,COL2,.. COLn
FROM TAB1
WHERE COL1 = 'XYZ' AND COL7 LIKE :WS-FIND


You can then test on the first column which query returned your row, if any. You might get more than one row back if more than one column satisfied the query.

I think a solution with some logic in the column list could do the trick, but I will let you do your own lookup for that in the SQL manual, and then come back if you have questions.
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1280
Location: Belgium

PostPosted: Fri Jan 21, 2011 3:52 pm    Post subject:
Reply with quote

Something like this
Code:
select
col1, case when col1 like ? then 'TRUE' else 'FALSE' end as Col1_cond,
col2, case when col2 like ? then 'TRUE' else 'FALSE' end as Col2_cond,
col3, case when col3 like ? then 'TRUE' else 'FALSE' end as Col3_cond,
col4, case when col4 like ? then 'TRUE' else 'FALSE' end as Col4_cond,
from table1
where ...
would avoid the possible n index-/tablescans of previous solution
and only returns each row only once.
Back to top
View user's profile Send private message
Kjeld

Active User


Joined: 15 Dec 2009
Posts: 365
Location: Denmark

PostPosted: Fri Jan 21, 2011 4:15 pm    Post subject:
Reply with quote

Yes, exactly wthat I was thinking of, but I would have to look the syntax up in the manual, not having done much work on this kind of statements.

And then I thought, better let the OP look it up first. But there it is, on a silver plate!
36_16_15.gif
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
This topic is locked: you cannot edit posts or make replies. DB2 query Using Recursion, Converting... smilewithashu2 DB2 3 Tue Jan 03, 2017 12:50 pm
No new posts find particular member name in PDS us... ravi243 CLIST & REXX 10 Mon Dec 19, 2016 6:44 pm
No new posts How to find the first monday of the w... abdulrafi COBOL Programming 10 Fri Nov 25, 2016 3:24 pm
No new posts SQZ pipe delimited file with 1 column... Rick Silvers DFSORT/ICETOOL 6 Sun Nov 06, 2016 8:11 pm
No new posts Find out a active PGM jpsager JCL & VSAM 10 Fri Oct 07, 2016 4:32 pm


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