Page 1 of 1

Selecting Like Clause parameters

PostPosted: Tue Jan 31, 2012 3:49 am
by daffodil17
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

Re: Selecting Like Clause parameters

PostPosted: Tue Jan 31, 2012 6:51 pm
by Nik22Dec
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!!