Solved

Query not working

Posted on 2014-01-18
9
262 Views
Last Modified: 2014-01-18
I am trying to build a query that is both a left and right join. It is saying "The SELECT statement includes a reserved word or argument name that is misspelled or missing, or the punctuation is incorrect."

My query is:

SELECT A.MessagesRecorded, A.TotalNewClients, A.BookedTrue, A.TalkedTo, A.PercentBooked, A.FiveMinCallBack, A.PercentinFive, A.DateField, B.SumOfSumOfExtendedPrice as B.SumOfSumOfExtendedPrice
FROM qryStatsIndividual as A
LEFT JOIN qryBookingDayswithYearII B
ON A.DateField = B.DateField
UNION ALL
SELECT NULL AS MessagesRecorded, NULL AS TotalNewClients, NULL AS BookedTrue, NULL AS TalkedTo, NULL AS PercentBooked, NULL AS FiveMinCallBack, NULL AS PercentinFive, B.DateField, B.SumOfSumOfExtendedPrice
FROM qryBookingDayswithYearII as B
LEFT JOIN qryStatsIndividual A
ON B.DateField = A.DateField
WHERE A.DateField IS NULL
0
Comment
Question by:cansevin
9 Comments
 
LVL 57
ID: 39790670
You missed an AS:

LEFT JOIN qryBookingDayswithYearII B

should be

LEFT JOIN qryBookingDayswithYearII AS B

Jim.
0
 

Author Comment

by:cansevin
ID: 39790675
Just fixed that, thanks! Still giving me the same error:

SELECT A.MessagesRecorded, A.TotalNewClients, A.BookedTrue, A.TalkedTo, A.PercentBooked, A.FiveMinCallBack, A.PercentinFive, A.DateField, B.SumOfSumOfExtendedPrice as B.SumOfSumOfExtendedPrice
FROM qryStatsIndividual as A
LEFT JOIN qryBookingDayswithYearII AS B
ON A.DateField = B.DateField
UNION ALL
SELECT NULL AS MessagesRecorded, NULL AS TotalNewClients, NULL AS BookedTrue, NULL AS TalkedTo, NULL AS PercentBooked, NULL AS FiveMinCallBack, NULL AS PercentinFive, B.DateField, B.SumOfSumOfExtendedPrice
FROM qryBookingDayswithYearII as B
LEFT JOIN qryStatsIndividual A
ON B.DateField = A.DateField
WHERE A.DateField IS NULL
0
 
LVL 57
ID: 39790677
BTW, same thing here:

LEFT JOIN qryStatsIndividual A

Should be:

LEFT JOIN qryStatsIndividual As A

Jim.
0
 
LVL 57
ID: 39790679
Also, just to be clear, each statement before and after the UNION ALL needs to stand on it's own.

Copy/Paste each statement into the query desinger when in SQL view and see if they fly.

Jim.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:cansevin
ID: 39790684
Unfortunately, it's still doing it. What do you mean by Copy/Past each statement? Where would the error be? I miss spell a field name?
0
 
LVL 30

Expert Comment

by:hnasr
ID: 39790703
To show the idea using simple tables:
a(a, ...)
a
1
2
4

b(b, ...)
1
2
5

Select a.a, b.b From a Left Join b On a.a=b.b
Union All
Select a.a, b.b From b Left Join a On b.a=a.b;

a b
1 1
2 2
4
  5

Open in new window

0
 
LVL 57

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 500 total points
ID: 39790712
If you go into the query designer in Access, you can set the view to either:

1. Design - Where you get the grid to construct a query
2. Datasheet - Where you see the results
3. SQL - View.

 So you can work this one of two ways:

1. Design your query using design view, then switch to SQL view to see the resulting statement.

2. Cut and paste a SQL statement into the query when it's in SQL view, then switch to design view.

  If your having trouble with a statement, you can break it up (do the select first, then add on the Where, Order by, etc).

 This really helps a lot when doing SQL statements in code.

 I don't see anything right off and since it's not overly complicated, I would suggest doing #1.  

  You can do this for each of the selects, then in SQL view UNION ALL them to test the complete statement once you have the two individual selects working.

 Note that you won't be able to switch to design view for the UNION.  The graphical query designer can't do a Union or SQL pass through that way.

Jim.
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 39790729
try this


SELECT A.MessagesRecorded, A.TotalNewClients, A.BookedTrue, A.TalkedTo, A.PercentBooked, A.FiveMinCallBack, A.PercentinFive, A.DateField, B.SumOfSumOfExtendedPrice
FROM qryStatsIndividual as A
LEFT JOIN qryBookingDayswithYearII AS B
ON A.DateField = B.DateField
UNION ALL
SELECT NULL AS MessagesRecorded, NULL AS TotalNewClients, NULL AS BookedTrue, NULL AS TalkedTo, NULL AS PercentBooked, NULL AS FiveMinCallBack, NULL AS PercentinFive, B.DateField, B.SumOfSumOfExtendedPrice
FROM qryBookingDayswithYearII as B
LEFT JOIN qryStatsIndividual A
ON B.DateField = A.DateField
WHERE A.DateField IS NULL
0
 

Author Closing Comment

by:cansevin
ID: 39790758
Thanks for your help Jim! It worked. Now it is giving me some "overflow" problem. I'll open another question for that. Thanks again!
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

760 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

20 Experts available now in Live!

Get 1:1 Help Now