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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 How to do COLUMN IN (v1,v2,v2) with a LIKE

Author  Topic 

ronstone
Starting Member

32 Posts

Posted - 2002-05-10 : 17:50:32

I have a query which compares a column to a group (select statement).

Example:

SELECT * FROM CarsRec WHERE BrandName IN (SELECT BrandName FROM BrandRec)

But I need to use a Like, because in BrandRec, some BrandNames will contain Ma% or Fo% in addition to Ford and Mazda.

How do I:

SELECT * FROM CarsRec WHERE BrandName LIKE (SELECT BrandName from BrandRec)

???

Hope that is a good picture,
Ron



VyasKN
SQL Server MVP & SQLTeam MVY

313 Posts

Posted - 2002-05-11 : 07:39:04
Try this:

SELECT *
FROM CarsRec c
WHERE EXISTS
(
SELECT 1
FROM BrandRec b
WHERE b.BrandName LIKE LEFT(c.BrandName, 2) + '%'
)

Next time please post table structures, sample data and desired output, so that it's easier for us to work on it.


--
HTH,
Vyas
http://vyaskn.tripod.com
Go to Top of Page
   

- Advertisement -