A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

BUILDING UNION QUERY



 
 
Thread Tools Display Modes
  #1  
Old March 19th, 2010, 10:45 PM posted to microsoft.public.access.queries
JB
external usenet poster
 
Posts: 290
Default BUILDING UNION QUERY

I HAVE 2 QUERIES FROM 2 SEPARATE TABLES
ONE HAS THE TREATMENT SALES FOR THERAPIST BY DATE
ONE HAS THE RETAIL SALES FOR THERAPIST BY DATE
I JOIN THE INFORMATION FROM BOTH QUERIES INTO ONE USING UNION QUERY. I HAVE
TRIED USING THIS BELOW:
SELECT tblTherapistInformation.TherapistID,
tblTherapistInformation.TypeOfTherapist, [LastName] & " " & [FirstName] AS
[Therapist Name], tblRetailSales.[Transaction Date], tblRetailSales.[Retail
Sales]
FROM tblTherapistInformation INNER JOIN tblRetailSales ON
tblTherapistInformation.TherapistID = tblRetailSales.EmployeeID
WHERE (((tblTherapistInformation.TypeOfTherapist)=[ENTER TYPEOFTHERAPIST])
AND ((tblRetailSales.[Transaction Date]) Between [BeginDate] And [EndDate]))
UNION ALL
SELECT tblTherapistInformation.TherapistID,
tblTherapistInformation.TypeOfTherapist, [LastName] & " " & [FirstName] AS
[Therapist Name], tblWork.[Transaction Date], tblWork.[Treatment Sales]
FROM tblTherapistInformation INNER JOIN tblWork ON
tblTherapistInformation.TherapistID = tblWork.TherapistID
WHERE (((tblTherapistInformation.TypeOfTherapist)=[ENTER TYPEOFTHERAPIST])
AND ((tblWork.[Transaction Date]) Between [BeginDate] And [EndDate]));

I ONLY GET THE INFORMATION FROM THE FIRST QUERY AND NOT THE 2ND QUERY
HELP

  #2  
Old March 19th, 2010, 11:52 PM posted to microsoft.public.access.queries
John W. Vinson
external usenet poster
 
Posts: 18,261
Default BUILDING UNION QUERY

On Fri, 19 Mar 2010 15:45:01 -0700, JB wrote:

I HAVE 2 QUERIES FROM 2 SEPARATE TABLES
ONE HAS THE TREATMENT SALES FOR THERAPIST BY DATE
ONE HAS THE RETAIL SALES FOR THERAPIST BY DATE
I JOIN THE INFORMATION FROM BOTH QUERIES INTO ONE USING UNION QUERY. I HAVE
TRIED USING THIS BELOW:
SELECT tblTherapistInformation.TherapistID,
tblTherapistInformation.TypeOfTherapist, [LastName] & " " & [FirstName] AS
[Therapist Name], tblRetailSales.[Transaction Date], tblRetailSales.[Retail
Sales]
FROM tblTherapistInformation INNER JOIN tblRetailSales ON
tblTherapistInformation.TherapistID = tblRetailSales.EmployeeID
WHERE (((tblTherapistInformation.TypeOfTherapist)=[ENTER TYPEOFTHERAPIST])
AND ((tblRetailSales.[Transaction Date]) Between [BeginDate] And [EndDate]))
UNION ALL
SELECT tblTherapistInformation.TherapistID,
tblTherapistInformation.TypeOfTherapist, [LastName] & " " & [FirstName] AS
[Therapist Name], tblWork.[Transaction Date], tblWork.[Treatment Sales]
FROM tblTherapistInformation INNER JOIN tblWork ON
tblTherapistInformation.TherapistID = tblWork.TherapistID
WHERE (((tblTherapistInformation.TypeOfTherapist)=[ENTER TYPEOFTHERAPIST])
AND ((tblWork.[Transaction Date]) Between [BeginDate] And [EndDate]));

I ONLY GET THE INFORMATION FROM THE FIRST QUERY AND NOT THE 2ND QUERY
HELP


First off... please turn off your CAPS LOCK. It's hard to read and looks like
SHOUTING.

Then... if you open the second query by itself, not as part of the UNION, do
you see the tblWork results?


--

John W. Vinson [MVP]
  #3  
Old March 20th, 2010, 02:16 AM posted to microsoft.public.access.queries
Afrosheen via AccessMonster.com
external usenet poster
 
Posts: 70
Default BUILDING UNION QUERY

Pay attention to John closely. He's help me out with developing union queries.


Thanks John.

John W. Vinson wrote:
I HAVE 2 QUERIES FROM 2 SEPARATE TABLES
ONE HAS THE TREATMENT SALES FOR THERAPIST BY DATE

[quoted text clipped - 20 lines]
I ONLY GET THE INFORMATION FROM THE FIRST QUERY AND NOT THE 2ND QUERY
HELP


First off... please turn off your CAPS LOCK. It's hard to read and looks like
SHOUTING.

Then... if you open the second query by itself, not as part of the UNION, do
you see the tblWork results?


--
Message posted via http://www.accessmonster.com

  #4  
Old March 20th, 2010, 01:22 PM posted to microsoft.public.access.queries
John Spencer
external usenet poster
 
Posts: 7,815
Default BUILDING UNION QUERY

I suspect that you have a parameter problem and that your date parameters are
not being correctly interpreted. I would try declaring the parameter types.

PARAMETERS [ENTER TYPEOFTHERAPIST] Text(255), [BeginDate] Datetime
, [EndDate] DateTime;
SELECT tblTherapistInformation.TherapistID,
tblTherapistInformation.TypeOfTherapist
, [LastName] & " " & [FirstName] AS [Therapist Name]
, tblRetailSales.[Transaction Date]
, tblRetailSales.[Retail Sales]
FROM tblTherapistInformation INNER JOIN tblRetailSales ON
tblTherapistInformation.TherapistID = tblRetailSales.EmployeeID
WHERE (((tblTherapistInformation.TypeOfTherapist)=[ENTER TYPEOFTHERAPIST])
AND ((tblRetailSales.[Transaction Date]) Between [BeginDate] And [EndDate]))
UNION ALL
SELECT tblTherapistInformation.TherapistID,
tblTherapistInformation.TypeOfTherapist
, [LastName] & " " & [FirstName] AS [Therapist Name]
, tblWork.[Transaction Date]
, tblWork.[Treatment Sales]
FROM tblTherapistInformation INNER JOIN tblWork ON
tblTherapistInformation.TherapistID = tblWork.TherapistID
WHERE (((tblTherapistInformation.TypeOfTherapist)=[ENTER TYPEOFTHERAPIST])
AND ((tblWork.[Transaction Date]) Between [BeginDate] And [EndDate]));

If that does not work then try changing the where clauses to enforce the data
type.
Between CDate([BeginDate]) And CDate([EndDate])

And if none of this works, answer John Vinson's questions.

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

JB wrote:
I HAVE 2 QUERIES FROM 2 SEPARATE TABLES
ONE HAS THE TREATMENT SALES FOR THERAPIST BY DATE
ONE HAS THE RETAIL SALES FOR THERAPIST BY DATE
I JOIN THE INFORMATION FROM BOTH QUERIES INTO ONE USING UNION QUERY. I HAVE
TRIED USING THIS BELOW:
SELECT tblTherapistInformation.TherapistID,
tblTherapistInformation.TypeOfTherapist, [LastName] & " " & [FirstName] AS
[Therapist Name], tblRetailSales.[Transaction Date], tblRetailSales.[Retail
Sales]
FROM tblTherapistInformation INNER JOIN tblRetailSales ON
tblTherapistInformation.TherapistID = tblRetailSales.EmployeeID
WHERE (((tblTherapistInformation.TypeOfTherapist)=[ENTER TYPEOFTHERAPIST])
AND ((tblRetailSales.[Transaction Date]) Between [BeginDate] And [EndDate]))
UNION ALL
SELECT tblTherapistInformation.TherapistID,
tblTherapistInformation.TypeOfTherapist, [LastName] & " " & [FirstName] AS
[Therapist Name], tblWork.[Transaction Date], tblWork.[Treatment Sales]
FROM tblTherapistInformation INNER JOIN tblWork ON
tblTherapistInformation.TherapistID = tblWork.TherapistID
WHERE (((tblTherapistInformation.TypeOfTherapist)=[ENTER TYPEOFTHERAPIST])
AND ((tblWork.[Transaction Date]) Between [BeginDate] And [EndDate]));

I ONLY GET THE INFORMATION FROM THE FIRST QUERY AND NOT THE 2ND QUERY
HELP

  #5  
Old March 20th, 2010, 09:16 PM posted to microsoft.public.access.queries
John W. Vinson
external usenet poster
 
Posts: 18,261
Default BUILDING UNION QUERY

On Sat, 20 Mar 2010 09:22:04 -0400, John Spencer wrote:

I suspect that you have a parameter problem and that your date parameters are
not being correctly interpreted.


d'oh!

Thanks John. That has bitten me enough I should remember it!
--

John W. Vinson [MVP]
  #6  
Old March 22nd, 2010, 04:14 PM posted to microsoft.public.access.queries
JB
external usenet poster
 
Posts: 290
Default BUILDING UNION QUERY

John,
Yes when I run both queries separately I get the correct results.
Thanks
JB

"John W. Vinson" wrote:

On Fri, 19 Mar 2010 15:45:01 -0700, JB wrote:

I HAVE 2 QUERIES FROM 2 SEPARATE TABLES
ONE HAS THE TREATMENT SALES FOR THERAPIST BY DATE
ONE HAS THE RETAIL SALES FOR THERAPIST BY DATE
I JOIN THE INFORMATION FROM BOTH QUERIES INTO ONE USING UNION QUERY. I HAVE
TRIED USING THIS BELOW:
SELECT tblTherapistInformation.TherapistID,
tblTherapistInformation.TypeOfTherapist, [LastName] & " " & [FirstName] AS
[Therapist Name], tblRetailSales.[Transaction Date], tblRetailSales.[Retail
Sales]
FROM tblTherapistInformation INNER JOIN tblRetailSales ON
tblTherapistInformation.TherapistID = tblRetailSales.EmployeeID
WHERE (((tblTherapistInformation.TypeOfTherapist)=[ENTER TYPEOFTHERAPIST])
AND ((tblRetailSales.[Transaction Date]) Between [BeginDate] And [EndDate]))
UNION ALL
SELECT tblTherapistInformation.TherapistID,
tblTherapistInformation.TypeOfTherapist, [LastName] & " " & [FirstName] AS
[Therapist Name], tblWork.[Transaction Date], tblWork.[Treatment Sales]
FROM tblTherapistInformation INNER JOIN tblWork ON
tblTherapistInformation.TherapistID = tblWork.TherapistID
WHERE (((tblTherapistInformation.TypeOfTherapist)=[ENTER TYPEOFTHERAPIST])
AND ((tblWork.[Transaction Date]) Between [BeginDate] And [EndDate]));

I ONLY GET THE INFORMATION FROM THE FIRST QUERY AND NOT THE 2ND QUERY
HELP


First off... please turn off your CAPS LOCK. It's hard to read and looks like
SHOUTING.

Then... if you open the second query by itself, not as part of the UNION, do
you see the tblWork results?


--

John W. Vinson [MVP]
.

  #7  
Old March 22nd, 2010, 05:21 PM posted to microsoft.public.access.queries
John W. Vinson
external usenet poster
 
Posts: 18,261
Default BUILDING UNION QUERY

On Mon, 22 Mar 2010 09:14:01 -0700, JB wrote:

John,
Yes when I run both queries separately I get the correct results.
Thanks


Very odd. I can't see any reason that the query would lose data - you have
UNION ALL so it won't be trying to remove dups.

Try copying and pasting the SQL into Notepad; delete the query. If these
tables are linked from a backend, delete the link. Compact and repair the
database; relink the tables if needed; create a new query and copy and paste
the SQL. Something's evidently slightly corrupted!
--

John W. Vinson [MVP]
  #8  
Old March 22nd, 2010, 09:46 PM posted to microsoft.public.access.queries
JB
external usenet poster
 
Posts: 290
Default BUILDING UNION QUERY

Well I did that and still have the problem

"John W. Vinson" wrote:

On Mon, 22 Mar 2010 09:14:01 -0700, JB wrote:

John,
Yes when I run both queries separately I get the correct results.
Thanks


Very odd. I can't see any reason that the query would lose data - you have
UNION ALL so it won't be trying to remove dups.

Try copying and pasting the SQL into Notepad; delete the query. If these
tables are linked from a backend, delete the link. Compact and repair the
database; relink the tables if needed; create a new query and copy and paste
the SQL. Something's evidently slightly corrupted!
--

John W. Vinson [MVP]
.

  #9  
Old March 22nd, 2010, 10:40 PM posted to microsoft.public.access.queries
John W. Vinson
external usenet poster
 
Posts: 18,261
Default BUILDING UNION QUERY

On Mon, 22 Mar 2010 14:46:07 -0700, JB wrote:

Well I did that and still have the problem


I'm baffled then!

If the data is not confidential (or if you'll trust me with it), and the
database isn't too huge, I'd be willing to take a look at it. Compact the
database (the backend if it's split), put it in a zipped folder, and email it
to jvinson at wysard of info dot com (make the obvious edits) and I'll see
if I can figure out what's wrong.
--

John W. Vinson [MVP]
  #10  
Old March 23rd, 2010, 10:18 PM posted to microsoft.public.access.queries
JB
external usenet poster
 
Posts: 290
Default BUILDING UNION QUERY

John,
I emailed you the access file.
Thanks
JB

"John W. Vinson" wrote:

On Mon, 22 Mar 2010 14:46:07 -0700, JB wrote:

Well I did that and still have the problem


I'm baffled then!

If the data is not confidential (or if you'll trust me with it), and the
database isn't too huge, I'd be willing to take a look at it. Compact the
database (the backend if it's split), put it in a zipped folder, and email it
to jvinson at wysard of info dot com (make the obvious edits) and I'll see
if I can figure out what's wrong.
--

John W. Vinson [MVP]
.

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 04:27 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.