?
Solved

Query not working

Posted on 2014-01-18
9
Medium Priority
?
271 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 58
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 58
ID: 39790677
BTW, same thing here:

LEFT JOIN qryStatsIndividual A

Should be:

LEFT JOIN qryStatsIndividual As A

Jim.
0
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
LVL 58
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
 

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 31

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 58

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 2000 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 120

Expert Comment

by:Rey Obrero (Capricorn1)
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

649 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