DBquery not accepting condition like in Access

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
Semper
Junior Coder
Posts: 30
Joined: Mon Feb 25, 2008 3:28 pm

DBquery not accepting condition like in Access

Post by Semper » Thu Aug 22, 2013 11:27 am

Hi,

is this normal behaviour, it seems whenever i put the condition like in the DBQuery SQL statement i end up with 0 results.

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Aug 22, 2013 1:37 pm

I've got a half dozen scripts that have dbQuery using "like" so I'm certain there is nothing wrong with using "like". Are you sure about your connection string? Do you have and example of an SQL line that works and an example using "like" that fails?

EnderFFX
Pro Scripter
Posts: 92
Joined: Mon Mar 08, 2004 6:17 am

Re: DBquery not accepting condition like in Access

Post by EnderFFX » Thu Aug 22, 2013 6:22 pm

Semper wrote:Hi,

is this normal behaviour, it seems whenever i put the condition like in the DBQuery SQL statement i end up with 0 results.
I've done about a dozen or so, every time I've come across a 0 result it is because of a mistake in my Query.

Give us the Query and let us take a look!

Semper
Junior Coder
Posts: 30
Joined: Mon Feb 25, 2008 3:28 pm

Post by Semper » Thu Aug 22, 2013 8:45 pm

The thing is, i'm not writing the SQL statements in DBQuery, i have queries in access which i pass to DBQuery. That worked good for months.

Until I changed something in those querys after which i got 0 results.
And when i run that same query in access, i get the results.

After digging i realised i added the LIKE '*something*' (with wildcards)
So my concerne is a query working in access but not in MS.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Fri Aug 23, 2013 6:09 am

SQL usually wants % for wildcards not *.

Try % instead.

Remember that outside of Access the SQL syntax depends on the ODBC/ADO driver you are using. Not everything that works inside of Access may be supported by the connection driver you are using.

Like clauses and wildcards are absolutely supported and we use them all the time ... But the syntax is entirely dependent on the ODBC/ADO drivers you are using defined by the connection string. Macro scheduler simply passes the query to the driver. Macro Scheduler does NO processing or checks with the SQL - it doesn't know anything about it - it simply passes it on to the driver and database you have specified. So really, you need to look at the docs for the database/driver you are using.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Semper
Junior Coder
Posts: 30
Joined: Mon Feb 25, 2008 3:28 pm

Post by Semper » Fri Aug 23, 2013 7:28 am

I thought as much, thanks.

I finally replaced the * with % wildcard in Access query.
Now when i run it in Access it shows up 0 results because Access don't deal with %, but passing that same query in MS shows the records correctly and that is what i need.

Thanks again.

EnderFFX
Pro Scripter
Posts: 92
Joined: Mon Mar 08, 2004 6:17 am

Post by EnderFFX » Fri Aug 23, 2013 6:42 pm

Semper wrote:I thought as much, thanks.

I finally replaced the * with % wildcard in Access query.
Now when i run it in Access it shows up 0 results because Access don't deal with %, but passing that same query in MS shows the records correctly and that is what i need.

Thanks again.
Please post the code, and post the table structure/fields. This is my area of expertise and I may be able to help.

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Sat Aug 24, 2013 7:27 am

EnderFFX wrote:Please post the code, and post the table structure/fields. This is my area of expertise and I may be able to help.
Yeah, Semper, please post your (partial) script here so we all can learn from you and EnderFX, please. Thanks.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Sun Aug 25, 2013 9:11 am

Looks like the issue is solved so not sure why you want to see table structure.

Access has its own syntax INSIDE Access which is not necessarily standard SQL. E.g. it can use * as wildcard. But the standard for wildcards in SQL is % and it would appear that the JET/ODBC/ADO driver (whatever is being specified in Macro Scheduler for the DB connection) wants %.

But inside Access, Access wants *.

So in Access stick with the * but when you port your SQL into Macro Scheduler use % (Unless you know of a connection driver which can handle the * but in my experience all connection drivers want %).

Actually a Google search reveals that some versions of the Access ODBC driver can handle *. See:

http://kbalertz.com/234525/Running-Stor ... sults.aspx

So, as I said originally, the behaviour is determined by the connection driver you are using. There's a difference between what Access can use *internally* and what syntax is supported by the connection driver you are asking Macro Scheduler to use. And as shown in the above page there can be differences between one driver and another.

Remember that Macro Scheduler works BLIND. It cares not about the SQL you give it and doesn't understand it - it is just a messenger and simply passes it on to the connection driver.

Complain to Microsoft about the inconsistency not us. ;-)
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

EnderFFX
Pro Scripter
Posts: 92
Joined: Mon Mar 08, 2004 6:17 am

Post by EnderFFX » Wed Aug 28, 2013 3:02 pm

Marcus Tettmar wrote:Looks like the issue is solved so not sure why you want to see table structure.
I can't tell you how many times I've been debugging SQL queries for hours when it turned out a table field was given a type that was inconsistent with the query.

For some reason i read the very last message as the problem was not still open... I reread it today and realized he had the solution.

When posting SQL questions it is important to post:
the SQL query
the error message
the table structure

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Wed Aug 28, 2013 10:05 pm

EnderFFX wrote:When posting SQL questions it is important to post:
the SQL query
the error message
the table structure
Thanks EnderFFX.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts