Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 like and inlist

Author  Topic 

albertkohl
Aged Yak Warrior

740 Posts

Posted - 2007-03-26 : 13:25:49
is there any way to incorporate a like and an in () together?


for example, i want to pull all of the companies that match a list i have (10 companies) the normal way i would do this is just union together 10 quries, and basically query up each company, one by phone.

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2007-03-26 : 13:35:42
You'll have to use OR to put the LIKE tests together

SELECT ...
FROM yourtable
WHERE col1 LIKE 'string1%' OR col1 LIKE 'string2%' OR col1 LIKE 'string3%'
OR col1 LIKE 'string4%' OR col1 LIKE 'string5%' OR col1 LIKE 'string6%'
OR col1 LIKE 'string7%' OR col1 LIKE 'string8%' OR col1 LIKE 'string9%'
OR col1 LIKE 'string10%'
Go to Top of Page

albertkohl
Aged Yak Warrior

740 Posts

Posted - 2007-03-26 : 13:44:17
ouch, so no way really to work a like and an in together hu? okay, well i guess i could always just use excel to concant the statements. thank you!
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2007-03-26 : 13:48:16
Or....

You can create a work table, load it and do a theta join to it

on Col LIKE newCol+'%'

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 2007-03-26 : 19:53:29
something like

select a.* from a
inner join
(
select 'string1%' z union all
select 'string2%' union all
select 'string3%'
) b on a.z like b.z
Go to Top of Page
   

- Advertisement -