[AccessD] Wrong number of records returned in Union query

Hale, Jim Jim.Hale at FleetPride.com
Mon Apr 9 12:55:21 CDT 2007


That did the trick! Thanks
Jim Hale

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Gustav Brock
Sent: Monday, April 09, 2007 12:01 PM
To: accessd at databaseadvisors.com
Subject: Re: [AccessD] Wrong number of records returned in Union query


Hi Jim

You are on the track. You need: 

  UNION ALL

/gustav

>>> Jim.Hale at fleetpride.com 09-04-2007 18:39 >>>
I have a simple select  query that returns a different number of records
when it is run by itself than when it is run inside a union query. I believe
it is because duplicate records (which I need) are being dropped.  I have
tried the distinct and distinctrow key words in the union query to no avail.
Can someone tell me how to fix this? Thanks

The SQL for the union query is as follows ( the first query is the broken
one:

SELECT  DISTINCT qryPlanCapex_sub.fldCOMPY, qryPlanCapex_sub.fldDEPT,
qryPlanCapex_sub.Name, qryPlanCapex_sub.fldProjectNo,
qryPlanCapex_sub.fldDescr, qryPlanCapex_sub.fldYr, qryPlanCapex_sub.fldQtr,
qryPlanCapex_sub.fldAmt, qryPlanCapex_sub.Kind, qryPlanCapex_sub.fldRegion,
qryPlanCapex_sub.PlanPrNO, qryPlanCapex_sub.fldArea FROM qryPlanCapex_sub;
Union SELECT qryYTD_Capex_ApprovedAmt_sub.fldCOMPY,
qryYTD_Capex_ApprovedAmt_sub.fldDEPT, qryYTD_Capex_ApprovedAmt_sub.Name,
qryYTD_Capex_ApprovedAmt_sub.CAR_Number,
qryYTD_Capex_ApprovedAmt_sub.Description, qryYTD_Capex_ApprovedAmt_sub.Yr,
qryYTD_Capex_ApprovedAmt_sub.Qtr, qryYTD_Capex_ApprovedAmt_sub.CAR_Amount,
qryYTD_Capex_ApprovedAmt_sub.Kind, qryYTD_Capex_ApprovedAmt_sub.fldRegion,
qryYTD_Capex_ApprovedAmt_sub.Internal_Asset_ID,
qryYTD_Capex_ApprovedAmt_sub.GLMBRANCHES.fldArea
FROM qryYTD_Capex_ApprovedAmt_sub;
UNION
SELECT qryYTD_Capex_sub.fldCOMPY, qryYTD_Capex_sub.fldDEPT,
qryYTD_Capex_sub.Name, qryYTD_Capex_sub.CAR_Number,
qryYTD_Capex_sub.Description, qryYTD_Capex_sub.Yr, qryYTD_Capex_sub.Qtr,
qryYTD_Capex_sub.Acquired_Value, qryYTD_Capex_sub.Kind,
qryYTD_Capex_sub.fldRegion,
qryYTD_Capex_sub.Internal_Asset_ID,qryYTD_Capex_sub.GLMBRANCHES.fldArea
FROM qryYTD_Capex_sub;



-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com

***********************************************************************
The information transmitted is intended solely for the individual or
entity to which it is addressed and may contain confidential and/or
privileged material. Any review, retransmission, dissemination or
other use of or taking action in reliance upon this information by
persons or entities other than the intended recipient is prohibited.
If you have received this email in error please contact the sender and
delete the material from any computer. As a recipient of this email,
you are responsible for screening its contents and the contents of any
attachments for the presence of viruses. No liability is accepted for
any damages caused by any virus transmitted by this email.


More information about the AccessD mailing list