Forums

This topic is locked

Using the LIKE statement

Posted 15 Aug 2003 15:42:08
1
has voted
15 Aug 2003 15:42:08 Bec C posted:
I have a field (called parentID) in a database with numeric values separated by a comma
e.g. 2,12,18,22,40

I would like to find records based on a user selection that will look
up the values in this comma list. I use this statement at the moment:

SELECT * FROM QUESTIONS WHERE parentID LIKE '%' & '2' & '%' The only
problem is it finds records whenever 2 occurs such as 22,24,32,42 and
not just the 2.

How do I only find the record with 2 or is it impossible due to the
way I have built the field data?

Replies

Replied 21 Aug 2003 08:51:05
21 Aug 2003 08:51:05 Mark Tait replied:
Hi bex_c - try:

(If myNumList = 2,12,18,22,40)

"SELECT * FROM QUESTIONS WHERE parentID IN (" & myNumList & ""

That should only find the records with parentID in myNumList - and not (eg) 32, 42, 102 etc.

Cheers, Mark
www.fixitks.co.uk - knowledge bases, document management, faqs...

Mark Tait

Reply to this topic