Solved

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

Posted on 2013-06-07
8
457 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
Comment Utility
I would start by removing all the parentheses
0
 
LVL 15

Author Comment

by:David L. Hansen
Comment Utility
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
Comment Utility
Ok, then it looks like you are missing a set for the final query in each part of your union
0
 
LVL 18

Expert Comment

by:UnifiedIS
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 15

Accepted Solution

by:
David L. Hansen earned 0 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Found the bug on my own.  Very grateful for someone looking at it with me though.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now