Selecting Like Clause parameters



IBM's flagship relational database management system

Selecting Like Clause parameters

Postby daffodil17 » Tue Jan 31, 2012 3:49 am

Hi,

Need some help here. I'm thinking it might be a simple one and perhaps I am not getting it.

I am trying to generate results from a query:

Select
address_1,
City,
number_employees,
store_timings,
store_name
from
grocery_store
where
store_name like 'Wa%' or like 'Ral%' or like 'Targ%'
and ---
and---
with ur;

Now, in the resultset, I also require the like parameters that each row matched with come up. Is there a way I can do that? Please help.

Eg:
Address_1 City Number_Employees store_timings store_name param
------------ ---- ----------------------- ---------------- -------------- --------
some add cty 100 9am-6pm Walmart Wa
daffodil17
 
Posts: 1
Joined: Tue Jan 31, 2012 3:08 am
Has thanked: 0 time
Been thanked: 0 time

Re: Selecting Like Clause parameters

Postby Nik22Dec » Tue Jan 31, 2012 6:51 pm

Hi,

You can use CASE to achieve that. An example could be -

SELECT A.COL1,                           
CASE                                     
WHEN A.COL1 LIKE 'MICE%' THEN 'MICE'   
WHEN A.COL1 LIKE 'CAT%' THEN 'CAT' END
FROM DB2.TABLE1 A                         
WHERE A.COL1 LIKE 'MICE%' OR             
A.COL1 LIKE 'CAT%';


Hope it helps!!
Thanks,
Nik
User avatar
Nik22Dec
 
Posts: 68
Joined: Mon Dec 26, 2011 6:38 pm
Has thanked: 2 times
Been thanked: 0 time


Return to DB2

 


  • Related topics
    Replies
    Views
    Last post