SELECT statement with LIKE operator in Base Macro

Hi,

I want to perform the SQL statement below in a Base macro

SELECT "Country Code", "Postcodes", "Zone" FROM "tblZone" WHERE "Country Code" = 'GB' AND "Postcodes" LIKE '%WA%'

The Country Code and Postcodes criteria are coming from a form so variables will be used… In basic this will result in something like this:

stSQL = "SELECT ""Country Code"", ""Postcodes"", ""Zone"" FROM ""tblZone"" WHERE ""Country Code"" = '"+ccode+"' AND ""Postcodes"" LIKE '%"+DestPC+"%'"

I’m having trouble to get the right notation for the LIKE operator. The Statement before the LIKE operator works fine.

How do I get the LIKE operator to work??

Hello,

What problem are you having? The statement basically looks OK. It would also help to know what database you are using - default, split (version), MySQL, PostgreSQL, etc.

It fails to to proces the LIKE Operator… I’m using HSQLDB for the moment…
as described above the SELECT statement won’t run at all, no error message…

Hello,

With the info you have provided I cannot understand where your problem lies. In order to try and assist, I have put together a Q&D sample based upon your statement. The form for running the macro is FindRecords. It contains two different executions on macros - one where case matters & one where case is ignored. This may be part of your problem. Use the entries in the table to help in searching for records. Results will be displayed in a Message Box for each found record. If no results are found, you will get a message for that also.

Sample — PostCodesLike.odb

Thanks! I will check this!