Chat with a LIVE Microsoft Access Expert!
 
       
 

         

   

Go Back   Access World Forums > Microsoft Access Discussion > Queries

 
 
Chat with a LIVE Microsoft Access Expert!
Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 02-05-2004, 03:05 PM
Groundrush's Avatar
Groundrush Groundrush is offline
Blue Skies
 
Join Date: Apr 2002
Posts: 1,178
Groundrush is on a distinguished road
Help with a Union qry

I know I have posted this before but I am still unable to sort this one out

I have a qry that that has an equal join between 2 other qrys, which works fine if there is data in both.

As soon as one of the qrys has no data to pull through it will not read the qry that has

I need something that will except both regardless of which qry has data to pull through...........if that makes any sense!

this is my qry:
SELECT qryHolidayHalfDayCount.ResourceName, Nz([HolidayCount],0)+Nz([HolidayHalfDayCount],0)/2 AS HolidaysTaken
FROM qryHolidayFullDayCount INNER JOIN qryHolidayHalfDayCount ON qryHolidayFullDayCount.ResourceName = qryHolidayHalfDayCount.ResourceName;

this is what "FOFA" has suggested:

"Your query is not what you want. It is because you have a equal join between the two querys that means ONLY if both are present. What you really need is a UNION ALL query that takes all the rows from the halfday count (divides by two) and a one that takes all the rows from the holiday count, groups by resourcename and sums the counts up. Basically"

I think FOFA'S suggestion is the way to go.
can anyone help me to get there?

this is my attempt at a Union All qry:
SELECT [ResourceName],[HolidayHalfDayCount]
FROM [qryHolidayHalfDayCount]
UNION ALL SELECT [ResourceName],[HolidayCount]
FROM [qryHolidayFullDayCount];


Thanks
__________________
When people look like ants, its time to open your parachute, but when ants look like people....don't bother.
Reply With Quote
Sponsored Links
  #2  
Old 02-05-2004, 08:21 PM
yippie_ky_yay's Avatar
yippie_ky_yay yippie_ky_yay is offline
Registered User
 
Join Date: Jul 2002
Location: Canada
Posts: 334
yippie_ky_yay
Hey Groundrush,

in a union query, the columns must match so in your example here:
SELECT [ResourceName],[HolidayHalfDayCount]
FROM [qryHolidayHalfDayCount]
UNION ALL SELECT [ResourceName],[HolidayCount]
FROM [qryHolidayFullDayCount];

you would need to make your second column have the same heading. To accomplish this, simply add the keyword "AS" followed by the new column name (this is called aliasing).

SELECT [ResourceName],[HolidayHalfDayCount] AS HolidayCount
FROM [qryHolidayHalfDayCount]
UNION
SELECT [ResourceName],[HolidayCount]
FROM [qryHolidayFullDayCount];

Try that out and see how close you get (note that I assumed that the two querries in refered to after the "FROM" each got you the results you needed).

-Sean
Reply With Quote
  #3  
Old 02-06-2004, 05:39 AM
Groundrush's Avatar
Groundrush Groundrush is offline
Blue Skies
 
Join Date: Apr 2002
Posts: 1,178
Groundrush is on a distinguished road
Sorted

Works now

thanks
__________________
When people look like ants, its time to open your parachute, but when ants look like people....don't bother.
Reply With Quote
Sponsored Links
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 07:47 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
(c) copyright 2009 Access World