Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple Like statments?

Status
Not open for further replies.

coicle

Programmer
Joined
Sep 25, 2003
Messages
8
Location
GB
Hi,
Is it possible to set up an SQL query to have multiple LIKE statements? for example, this is the code I have

strCode = 'A1001'

Select *
FROM Products
WHERE Code LIKE strCode

so if I wanted to pull say three different codes out of the data base how would it be possible? for example, 'A1001' and 'A2002' etc....
The data for each one found would then be put into a table.
Thanks, I hope this makes sense,
Dan
=|:|
 
DO you need to use LIKE rather than = ? If you do, ie you're passing in values with wildcards, then you need to have separate LIKE clauses:

Code:
SELECT * FROM products
WHERE code LIKE 'A1001%'
  OR code LIKE 'A2002%'
  ...

If you are passing in exact values then you can use an IN clause:

Code:
SELECT * FROM products
WHERE code IN ('A1001', 'A2002')

If you want to make a stored procedure and pass in a list of values to search for using IN then check out this FAQ:

Passing a list of values to a Stored Procedure
faq183-3979

--James
 
Thanks mate, the IN statment words beeeutifelly and its all dapper now,
thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top