Solved

Query not working

Posted on 2014-01-18
9
267 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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
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
 

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
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…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

730 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