tags:

views:

97

answers:

5

Consider this Access query:

SELECT prod_Parts.ID, prod_Parts.Number, prod_Parts.Revision, prod_Parts.Description
FROM prod_JT_Shipping 
INNER JOIN (prod_JobTraveller 
            INNER JOIN prod_Parts
                ON prod_JobTraveller.PartID = prod_Parts.ID) 
    ON prod_JT_Shipping.JT_ID=prod_JobTraveller.ID;

Also this:

 SELECT prod_Parts.ID, prod_Parts.Number, prod_Parts.Revision, prod_Parts.Description 
 FROM prod_Parts;

This error occurs on both:

'is not a valid name. Make sure that it does not include invalid characters or punctuation and that it is not too long

How can this be fixed?

+1  A: 

This part here doesn't look right:

INNER JOIN (prod_JobTraveller 
INNER JOIN prod_Parts ON prod_JobTraveller.PartID = prod_Parts.ID) 

If you consolidate that without whitespace it looks like

INNER JOIN (prod_JobTraveller INNER JOIN prod_Parts ON prod_JobTraveller.PartID = prod_Parts.ID) 

Which is not valid SQL.

Chris Thompson
It is legal to group joins using parentheses, though I've used it so rarely that I can't say for sure whether the OP's query is valid or not, but I think it is valid.
Marcelo Cantos
Doesn't work. Access breaks lines. I wrong copied and pasted. Anyway problem is presented
Igor
A straight cut-and-paste of the OP query into SQL view of the query design window will run.
Remou
Grouping joins with parentheses is not only valid, it's actually required in Access if you have more than one join.
Guffa
How is that invalid SQL? There's nothing wrong with it so far as I can see. Please explain exactly what characters in the SQL clause are invalid, or I'll downvote your answer. If you find you're mistaken, then just delete your answer.
David-W-Fenton
A: 

What happens if you take out the parenthesis?

egrunin
nothing happens, the same problem :(
Igor
The parenthesis should not be removed, Access requires them for the join illustrated.
Remou
A: 

You have to give this section below an alias:

(prod_JobTraveller 
            INNER JOIN prod_Parts
                ON prod_JobTraveller.PartID = prod_Parts.ID)

For instance, this may work:

(prod_JobTraveller 
            INNER JOIN prod_Parts
                ON prod_JobTraveller.PartID = prod_Parts.ID) prod_JobTraveller
K Richard
How properly to write full "FROM" clause? /*I'm not professional in SQL, this is temporarily*/
Igor
This is not a subquery, it is how Access deals with joins. It does not need an alias.
Remou
@K Richard Please re-examine your answer in the light of the ms-acces tag. I am afraid it is wrong.
Remou
The answer wouldn't be right for any other database, either. You can't alias as JOIN, only a field, table or a valid subquery.
David-W-Fenton
This answer is completely incorrect and should be deleted.
David-W-Fenton
A: 

OK. I have simplified query:

SELECT prod_Parts.ID, prod_Parts.Number, prod_Parts.Revision, prod_Parts.Description FROM prod_Parts;

The same error :)

Igor
Is `prod_Parts` a base table or a `VIEW` (persisted Query object)? Either way, posting SQL DDL to recreate it would help. `Number` is a reserved word in Access (ACE, Jet, whatever) but qualifying it in the SELECT clause with the table name shouldn't cause a problem.
onedaywhen
+1  A: 

Judging from the error message, you have some invisible control character in the query, that is causing the problem.

Try to retyping the query from scratch, and it will most likely work.

Side note: I find it easier to follow the joins if they are written in this order (i.e. with the ON clause directly following each JOIN):

SELECT
  prod_Parts.ID, prod_Parts.Number, prod_Parts.Revision, prod_Parts.Description
FROM
  (
    prod_JT_Shipping
    INNER JOIN prod_JobTraveller ON prod_JT_Shipping.JT_ID=prod_JobTraveller.ID
  )
  INNER JOIN prod_Parts ON prod_JobTraveller.PartID = prod_Parts.ID 
Guffa
I considered it. I did it before asking
Igor
Have you tried a stripped table? Have you check for corruption?
Remou