0

How do I convert this query to MS Access?

SELECT * FROM table WHERE (id='11101958' OR number LIKE '%t11101958%' OR name LIKE '%t11101958%') OR (dateofbirth='1958-10-11' AND SUBSTR(name,1,1)='t') ORDER BY name LIMIT 0,10;

I have already found out:

LIMIT 0,10 > TOP 10

dateofbirth='1958-10-11' AND SUBSTR(name,1,1)='t' > dateofbirth=#10-11-1958# AND LEFT(name,1)='t'

What I can't seem to find out is how to have 2 sets of "AND". So basically I have:

SELECT TOP 10 * FROM table WHERE (id='11101958' OR number LIKE '%t11101958%' OR name LIKE '%t11101958%') OR (dateofbirth=#10-11-1958# AND SUBSTR(name,1,1)='t') ORDER BY name;

Also: is it correct that I have to search for mm-dd-yyyy instead of dd-mm-yyyy or yyyy-mm-dd?

1
  • 1
    What do you mean by "Two sets of "AND"" There is only one AND in your original mysql query. I think you just need to change out Substr(name, 1, 1) = 't' to LEFT(name, 1) = "t" and then go back and change all of your single quotes to double for your string literals. Commented Jan 10, 2020 at 20:03

1 Answer 1

2

The equivalent of the wild char % in Access is *.
The equivalent of SUBSTR() is MID() but since you want only the 1st char then LEFT() works too.
Instead of LIMIT use TOP.
You can use the format yyyy-mm-dd for the dates:

SELECT TOP 10 * 
FROM table 
WHERE (id='11101958' OR number LIKE '*t11101958*' OR name LIKE '*t11101958*') 
   OR (dateofbirth=#1958-10-11# AND LEFT(name,1)='t') 
ORDER BY name
Sign up to request clarification or add additional context in comments.

5 Comments

Thank you, it almost works. When I add a string instead of an integer for "id" the query fails.
If the data type of the id is integer you should pass an integer or instead of id = '5' pass id = val('5')
BTW: TOP 10 doesn't seem to work. It simply shows the complete result set...
TOP 10 is the way to set the LIMIT in Access.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.