Solved

ACCESS SQL 'Syntax error in FROM clause' - Can you help me find the bug?

Posted on 2013-06-07
8
469 Views
Last Modified: 2013-06-12
The following SQL Statement apparently has a typo.  I can't find it though.  It should be an easy 500 points.  Here it is (remember it is Access):
SELECT DISTINCT VA.CallerID AS Client_ID, VB.[Date] AS Encounter, '1' AS Opt 
FROM ((((qry_Disability_Referral_Counts AS VA 
INNER JOIN qry_CallLog_Rel_CallType AS VB ON VB.Caller = VA.CallerID) 
INNER JOIN qry_Calls_Rel_Vet_Services AS VV On VV.Call_ID = VB.Call_ID) 
LEFT OUTER JOIN qry_War_Counts AS VW On VW.callerid = VA.CallerID) 
LEFT OUTER JOIN qry_Race_Counts AS VR On VR.callerid = VA.CallerID) 
LEFT OUTER JOIN qry_VA_Referral_ Counts AS VC ON VC.callerid = VA.CallerID 
WHERE VB.Call_Type_ID = 2 
UNION ALL 
SELECT DISTINCT VA.CallerID AS Client_ID, VB.[Date] AS Encounter, '0' AS Opt 
FROM ((((qry_Disability_Referral_Counts AS VA 
INNER JOIN qry_CallLog_Rel_CallType AS VB ON VB.Caller = VA.CallerID)
INNER JOIN qry_Calls_Rel_Vet_Services VV On VV.Call_ID = VB.Call_ID) 
LEFT OUTER JOIN qry_War_Counts AS VW On VW.callerid = VA.CallerID) 
LEFT OUTER JOIN qry_Race_Counts AS VR On VR.callerid = VA.CallerID) 
LEFT OUTER JOIN qry_VA_Referral_Counts AS VC ON VC.callerid = VA.CallerID 
WHERE VB.Call_Type_ID <> 2;

Open in new window

0
Comment
Question by:David L. Hansen
  • 4
  • 4
8 Comments
 
LVL 18

Expert Comment

by:UnifiedIS
ID: 39230258
I would start by removing all the parentheses
0
 
LVL 15

Author Comment

by:David L. Hansen
ID: 39230304
It's Access.  It is a requirement when working with multiple joins....see this link:
http://nm1m.blogspot.de/2007/10/multiple-left-joins-in-ms-access.html
I know...weird huh?
0
 
LVL 18

Expert Comment

by:UnifiedIS
ID: 39230315
Ok, then it looks like you are missing a set for the final query in each part of your union
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 18

Expert Comment

by:UnifiedIS
ID: 39230346
Are you able to use the Design view to build this query?  It doesn't look too complicated to create and then you can use the SQL view to see exactly what Access wants.
0
 
LVL 15

Accepted Solution

by:
David L. Hansen earned 0 total points
ID: 39230356
Found it.  There is an extra blank in the table name in the last LEFT OUTER JOIN (before the UNION ALL) just after one of the underscores. Wheew! Thanks though!
0
 
LVL 18

Expert Comment

by:UnifiedIS
ID: 39230360
I also notice in the link you provided that the first table is contained within parentheses but in your queries, they are not.

I think the from would then look like this with a 5th "(" and the ")" after the VA alias

FROM ((((qry_Disability_Referral_Counts AS VA)
0
 
LVL 15

Author Comment

by:David L. Hansen
ID: 39235407
You'd think huh?  But just changing that one space made the whole thing work superbly...go figure.
0
 
LVL 15

Author Closing Comment

by:David L. Hansen
ID: 39240448
Found the bug on my own.  Very grateful for someone looking at it with me though.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question