Using multiple criteria in Like Operator

  • Thread starter Thread starter Luqman
  • Start date Start date
L

Luqman

A table has article codes saved in a format of art1art2art3 (no commas or
any separator in between but all codes are of 03 chars).

Say the table data is as under:-

Code Name
art1art2 Item 1
art1 Item 2
art2 Item 3
art1art3 Item 4
art2art3 Item 5

Now I would like to search through query, all items having art1 or art3 in
code, how can I do so, please note, there could be more than 100 codes in
searh criteria.

The ways I know is either use union query

1ST EXAMPLE
===========
Select * from myTable
Where code like '%art1%'
Union
Select * from myTable
Where code like '%art3%'

2ND EXAMPLE
============
Select * from myTable
Where code like '%art1%'
OR
code like '%art3%'

If I save all my required searching codes in a table, how can I use those
values in query.

Something like :

select * from myTable
where code like
(select code from mySearch)

Please note, I cannot use 'code in' because the codes in mytable are saved
in a concatenation manner without any delimiters or seperators.

Any suggestions please ?

Best Regards,

Luqman
 
If you built this data structure, throw it out and build build a normalized
one. Multiple keys in a single field is an oxymoron.

If you are trying to parse someone else's data, create a table to store the
results in a normalized fashion. Then execute an append query using Mid() to
parse the Code field in a loop so that a separate record is created for each
of the multiples in the nonsense table.
 
Back
Top