SYNTAX ERROR when INNER JOIN (1 Viewer)

Bosve

Registered User.
Local time
Tomorrow, 00:56
Joined
Jan 27, 2010
Messages
35
Hi, I am having the following issue with the exact same SQL query

Window7 + Access 2013: INNER JOIN query works without issues on SQL tables

Windows 10 + Access 2016: exactly the same query: SYNTAX ERROR when INNER JOIN on SQL tables all other queries work fine.





 

Bosve

Registered User.
Local time
Tomorrow, 00:56
Joined
Jan 27, 2010
Messages
35
Provide query SQL statement.


SELECT DISTINCT BATCHSERIES.BATCHSERIESNO, STOCKTABLE.ITEMNAME, BATCHSERIES.BESKR1, BATCHSERIES.BESKR2, BATCHSERIES.BESKR3, BATCHSERIES.BESKR4, STOCKTABLE.ITEMNAME2UK, STOCKTABLE.ITEMNAME3UK, StockUnitConvert([STOCKUNIT]) AS Unit FROM BATCHSERIES INNER JOIN STOCKTABLE ON (BATCHSERIES.ITEMNUMBER = STOCKTABLE.ITEMNUMBER) AND (BATCHSERIES.DATASET = STOCKTABLE.DATASET) WHERE (((BATCHSERIES.STOCKSTATUS)=3) AND ((BATCHSERIES.DATASET)='AAB')) UNION SELECT '','********','','','','','','','' FROM BATCHSERIES

ORDER BY BATCHSERIES.BATCHSERIESNO;
 

June7

AWF VIP
Local time
Today, 14:56
Joined
Mar 9, 2014
Messages
5,465
Only thing I can think might be issue is asterisk characters which are wildcard in Access SQL. Why use these characters?
 

Cronk

Registered User.
Local time
Tomorrow, 08:56
Joined
Jul 4, 2013
Messages
2,771
asterisk characters which are wildcard in Access SQL
That would apply in a WHERE Clause but not in a SELECT field string.
 

June7

AWF VIP
Local time
Today, 14:56
Joined
Mar 9, 2014
Messages
5,465
Good point.

Still wonder why using asterisk characters.

I always use Null instead of empty string in UNION. That way not mixing number or date fields with empty string value.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 23:56
Joined
Feb 19, 2013
Messages
16,607
Would also help to know the exact wording of the syntax error.

Some thoughts

You don't need SELECT DISTINCT, just SELECT - a straight union query automatically use DISTINCT

perhaps the error is in your function StockUnitConvert

By SQL tables, I presume you mean SQL Server? In which case are your ODBC drivers correct?
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 17:56
Joined
Feb 28, 2001
Messages
27,138
Code:
'[COLOR="Red"](1)[/COLOR]' ,'********' [COLOR="red"](2)[/COLOR], '[COLOR="red"](3)[/COLOR]', '[COLOR="red"](4)[/COLOR]', '[COLOR="red"](5)[/COLOR]', '[COLOR="red"](6)[/COLOR]','[COLOR="red"](7)[/COLOR]','[COLOR="Red"](8)[/COLOR]','[COLOR="red"](9)[/COLOR]'

I added the numbers for clarity. The above, originating from the second part of the UNION, returns 9 fields, ALL of which are of type Text (because of the quoted strings.) The first part of the UNION also returns 9 fields, so that much is OK. However, are all of the field types in the first part of the UNION compatible? If anything other than the first field is numeric, you might have a type mismatch issue to consider.

EDIT: Revisited what was posted and realize I misread the first field. It, too, is a zero-length string. If ANY of the fields from the first SELECT in the UNION return a number, you have a type mismatch, but the UNION clause complicates matters and might lead to a SYNTAX error. I'm not sure what would happen there.
 
Last edited:

Bosve

Registered User.
Local time
Tomorrow, 00:56
Joined
Jan 27, 2010
Messages
35
Thank you for all the replies and I appreciate the time you took to understand my problem but your answers are currently too advanced for me. This Access application was not developed by me so I don't know in detail how it works. I was hoping for a quick solution like something obvious I am missing.

However one of you suggested ODBC drivers as a root cause which is very possible since I have issues with Excel documents that are fetching data from the same SQL DB as Access. Excel documents work flawlessly in W7/Office2013 but fail when opened in W10/Office2016 environment.
 

Users who are viewing this thread

Top Bottom