Skip to content
Advertisement

Returning values from a database with a Substring

Let’s say I’ve got 3 product description fields with the values AC-120 XXX, AC-120,CCC and AC-120 BBB.

How would I get that information from a table using only AC-120 as my search argument?

I’ve tried using the subStr function but that won’t return any values either

    SELECT TbArtikel.Artikel_Merk, TbArtikel.Artikel_Groep, TbArtikel.Artikel_Categorie_ID, TussenMAATenARTKEL.VoorraadNummer, TbArtikel.Artikel_ID, TussenMAATenARTKEL.ArtikelDetail_ID, TbArtikel.Artikel_Prijs_Advies, TbArtikel.Artikel_Prijs_Bees, TbArtikel.Artikel_Omschrijving
FROM TbArtikel INNER JOIN TussenMAATenARTKEL ON TbArtikel.Artikel_ID = TussenMAATenARTKEL.Artikel_ID
WHERE (((TbArtikel.Artikel_Merk)="Yonex") AND  ((TbArtikel.Artikel_Omschrijving)="%AC-102%"));

Advertisement

Answer

LIKE is very appropriate for this comparison. However, MS Access uses different wildcards from standard SQL. So you want:

TbArtikel.Artikel_Omschrijving) LIKE "*AC-102*"

In standard SQL, this would be:

TbArtikel.Artikel_Omschrijving) LIKE "%AC-102%"
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement