?
Solved

Query not working

Posted on 2014-01-18
9
Medium Priority
?
270 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
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…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Suggested Courses

741 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