adding another table to a union query

T

tim.hambly

Hey all! I know this should be simple but there must be something wrong
because it is not working. I created a query that pulls date into a table
from SharePoint. This data is broken up into different tables (Q1, Q2, Q3,
and Q4). Now there are two different types of tables I am combining. So
there is a Q1 table for phone work and a Q1 table for non phone work, the
same with Q2, Q3 and Q4. I successfully created a union query to display the
results of all phone work and non phone work for Q1 and Q2 combined but when
I try to add Q3 to the mix I am having no luck. Here is what the union query
looks like:

SELECT offlinequality.*
FROM offlinequality;
UNION ALL SELECT [Servicing Offline 2nd Qtr 2009].*
FROM [Servicing Offline 2nd Qtr 2009];
UNION ALL SELECT [Servicing Offline 3rd Qtr 2009].*
FROM [Servicing Offline 3rd Qtr 2009];

But the data from Servicing Offline 3rd Qtr 2009 does not pull into the report

Here is the phone work query:

SELECT phonequality.*
FROM phonequality;
UNION ALL SELECT [Servicing Phone 2nd Qtr 2009].*
FROM [Servicing Phone 2nd Qtr 2009];
UNION ALL SELECT [Servicing Phone 3rd Qtr 2009].*
FROM [Servicing Phone 3rd Qtr 2009];

Now the phone data from all Q's pulls into the report with not problem only
the non phone data is not displaying. The Query I made to pull both of these
queries together is:

SELECT offlineqry.RepName, offlineqry.Created, offlineqry.Totals,
offlineqry.OverallRating, offlineqry.ConTyp
FROM offlineqry
WHERE (((offlineqry.Created)>=[Enter Begin Date:] And
(offlineqry.Created)<=[Enter End Date:]) AND ((offlineqry.Supervisor)=[enter
supervisor's last name]))
UNION ALL SELECT phoneqry.RepName, phoneqry.Created, phoneqry.Totals,
phoneqry.OverallRating, phoneqry.ConTyp
FROM phoneqry
WHERE (((phoneqry.Created)>=[Enter Begin Date:] And
(phoneqry.Created)<=[Enter End Date:]) AND ((phoneqry.Supervisor)=[enter
supervisor's last name]));

Like I was saying I when I run the report I see the phone data for all Q's
but only the non phone data from Q1 and Q2. Am I doing something wrong here
that I am not seeing? Any help you can offer me would be fantastic. Thanks,
 
P

PieterLinden via AccessMonster.com

Tim,
define "not working".

If I were in your position, I would head the problem off before it starts.
If you are have already created the query that pulls the data you want, why
not just append it to a (previously emptied) table and include the Quarter,
if necessary. Then you don't need ANY union queries, you can index your
table, and then it will work properly.

Just from looking at your SQL statements, I can't tell how many fields each
statement contains. The first select statement in the union query determines
the number of columns the final result will contain.... so usually, those
fields listed explicitly, e.g.,

SELECT t1.F1 AS FirstName, t1.F2 AS LastName, t1.F3 AS Address
FROM t1
WHERE...
UNION ALL
SELECT t2.F1, t2.F2, t3.F3
FROM t2

tim.hambly said:
Hey all! I know this should be simple but there must be something wrong
because it is not working. I created a query that pulls date into a table
from SharePoint. This data is broken up into different tables (Q1, Q2, Q3,
and Q4). Now there are two different types of tables I am combining. So
there is a Q1 table for phone work and a Q1 table for non phone work, the
same with Q2, Q3 and Q4. I successfully created a union query to display the
results of all phone work and non phone work for Q1 and Q2 combined but when
I try to add Q3 to the mix I am having no luck. Here is what the union query
looks like:

SELECT offlinequality.*
FROM offlinequality;
UNION ALL SELECT [Servicing Offline 2nd Qtr 2009].*
FROM [Servicing Offline 2nd Qtr 2009];
UNION ALL SELECT [Servicing Offline 3rd Qtr 2009].*
FROM [Servicing Offline 3rd Qtr 2009];

But the data from Servicing Offline 3rd Qtr 2009 does not pull into the report

Here is the phone work query:

SELECT phonequality.*
FROM phonequality;
UNION ALL SELECT [Servicing Phone 2nd Qtr 2009].*
FROM [Servicing Phone 2nd Qtr 2009];
UNION ALL SELECT [Servicing Phone 3rd Qtr 2009].*
FROM [Servicing Phone 3rd Qtr 2009];

Now the phone data from all Q's pulls into the report with not problem only
the non phone data is not displaying. The Query I made to pull both of these
queries together is:

SELECT offlineqry.RepName, offlineqry.Created, offlineqry.Totals,
offlineqry.OverallRating, offlineqry.ConTyp
FROM offlineqry
WHERE (((offlineqry.Created)>=[Enter Begin Date:] And
(offlineqry.Created)<=[Enter End Date:]) AND ((offlineqry.Supervisor)=[enter
supervisor's last name]))
UNION ALL SELECT phoneqry.RepName, phoneqry.Created, phoneqry.Totals,
phoneqry.OverallRating, phoneqry.ConTyp
FROM phoneqry
WHERE (((phoneqry.Created)>=[Enter Begin Date:] And
(phoneqry.Created)<=[Enter End Date:]) AND ((phoneqry.Supervisor)=[enter
supervisor's last name]));

Like I was saying I when I run the report I see the phone data for all Q's
but only the non phone data from Q1 and Q2. Am I doing something wrong here
that I am not seeing? Any help you can offer me would be fantastic. Thanks,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Adding fields working for some records, not all 3
OUTER join problem 8
query error 12
Union query 5
calculated field in query 11
SUM in a UNION query 2
BUILDING UNION QUERY 10
determining if a field should be included 6

Top