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  

trouble with query results



 
 
Thread Tools Display Modes
  #1  
Old February 8th, 2007, 06:16 PM posted to microsoft.public.access.queries
Slez via AccessMonster.com
external usenet poster
 
Posts: 176
Default trouble with query results

I have a query that returns duplicate records as follows:

If I have 1 record in tblChangeItem, it returns the records for
tblChangeItemDetail properly.
If I have 2 records in tblChangeItem, it returns double the records for
tblChangeItemDetail.
If I have 3 records in tbleChangeItem, it returns the records for
tblChangeItemDetail in triplicate.
...and so on...

Right now, Unique Values and Unique Records is set to No. I have tried
seting them to Yes, but it did not change the results of the query. I
suspect that something with my JOINS in the query is not quite right, but
I've not been successful at identifying the problem. Any suggestions on
where to start? Thanks in advance for any help!

Here is my query's SQL:
SELECT Project.ProjectID, Project.ProjectName, Project.JobNumber,
tblChangeRequest.ChangeRequestID, tblChangeRequest.CRDate, tblChangeRequest.
Estimator, Project.SalesTax, Project.TaxExempt, tblChangeRequest.
SalesTaxAmount, tblChangeRequest.UseTaxAmount, tblChangeItem.RoomNumber & " -
" & tblChangeItem.ItemNumber AS ItemLabel, [Quantity]*([UnitPrice]+[QuoteCost]
) AS LineTotalCost, [LineTotalCost]*[Markup] AS SellPrice, [Quantity]*(
[QuoteCost]+[MaterialCost]) AS LineMaterialCost, [Quantity]*(
[MachineLaborHours]+[BuildingLaborHours]) AS LineTotalLabor,
tblChangeItemDetail.Quantity, tblChangeItemDetail.ProductDescription,
tblChangeItemDetail.Markup, tblChangeItemDetail.QuoteCost, Product.
ProductCode, Product.CBDCode, Product.MachineLaborHours, Product.
BuildingLaborHours, Product.MaterialCost, Product.UOM, Product.UnitCost,
Labor.CBDCodeID, Product.LibraryReference, tblChangeRequest.ChangeDescription,
tblChangeItem.ItemDescription

FROM ((Labor INNER JOIN Product ON Labor.CBDCode = Product.CBDCode) INNER
JOIN ((Project INNER JOIN tblChangeItem ON Project.ProjectID = tblChangeItem.
ProjectID) INNER JOIN tblChangeItemDetail ON (tblChangeItem.ChangeRequestID =
tblChangeItemDetail.ChangeRequestID) AND (tblChangeItem.ProjectID =
tblChangeItemDetail.ProjectID) AND (Project.ProjectID = tblChangeItemDetail.
ProjectID)) ON Product.ProductDescription = tblChangeItemDetail.
ProductDescription) INNER JOIN tblChangeRequest ON (tblChangeRequest.
ChangeRequestID = tblChangeItem.ChangeRequestID) AND (tblChangeRequest.
ProjectID = tblChangeItem.ProjectID) AND (Project.ProjectID =
tblChangeRequest.ProjectID)

ORDER BY Project.ProjectID, tblChangeItem.RoomNumber & " - " & tblChangeItem.
ItemNumber;

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...eries/200702/1

  #2  
Old February 8th, 2007, 07:26 PM posted to microsoft.public.access.queries
Jerry Whittle
external usenet poster
 
Posts: 4,732
Default trouble with query results

What are the primary keys fields for the following tables?

Labor
Product
Project
tblChangeItem
tblChangeItemDetail
tblChangeRequest

My bet is that you don't have a primary key or at least unique indexed
field(s) on one side of the join which you should have to ensure a
one-to-many relationship. In that case you could have duplicate matching
values on both sides of the join, AKA a many-to-many relationship, which can
cause the behavior that you are describing.
--
Jerry Whittle, Microsoft Access MVP
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.


"Slez via AccessMonster.com" wrote:

I have a query that returns duplicate records as follows:

If I have 1 record in tblChangeItem, it returns the records for
tblChangeItemDetail properly.
If I have 2 records in tblChangeItem, it returns double the records for
tblChangeItemDetail.
If I have 3 records in tbleChangeItem, it returns the records for
tblChangeItemDetail in triplicate.
...and so on...

Right now, Unique Values and Unique Records is set to No. I have tried
seting them to Yes, but it did not change the results of the query. I
suspect that something with my JOINS in the query is not quite right, but
I've not been successful at identifying the problem. Any suggestions on
where to start? Thanks in advance for any help!

Here is my query's SQL:
SELECT Project.ProjectID, Project.ProjectName, Project.JobNumber,
tblChangeRequest.ChangeRequestID, tblChangeRequest.CRDate, tblChangeRequest.
Estimator, Project.SalesTax, Project.TaxExempt, tblChangeRequest.
SalesTaxAmount, tblChangeRequest.UseTaxAmount, tblChangeItem.RoomNumber & " -
" & tblChangeItem.ItemNumber AS ItemLabel, [Quantity]*([UnitPrice]+[QuoteCost]
) AS LineTotalCost, [LineTotalCost]*[Markup] AS SellPrice, [Quantity]*(
[QuoteCost]+[MaterialCost]) AS LineMaterialCost, [Quantity]*(
[MachineLaborHours]+[BuildingLaborHours]) AS LineTotalLabor,
tblChangeItemDetail.Quantity, tblChangeItemDetail.ProductDescription,
tblChangeItemDetail.Markup, tblChangeItemDetail.QuoteCost, Product.
ProductCode, Product.CBDCode, Product.MachineLaborHours, Product.
BuildingLaborHours, Product.MaterialCost, Product.UOM, Product.UnitCost,
Labor.CBDCodeID, Product.LibraryReference, tblChangeRequest.ChangeDescription,
tblChangeItem.ItemDescription

FROM ((Labor INNER JOIN Product ON Labor.CBDCode = Product.CBDCode) INNER
JOIN ((Project INNER JOIN tblChangeItem ON Project.ProjectID = tblChangeItem.
ProjectID) INNER JOIN tblChangeItemDetail ON (tblChangeItem.ChangeRequestID =
tblChangeItemDetail.ChangeRequestID) AND (tblChangeItem.ProjectID =
tblChangeItemDetail.ProjectID) AND (Project.ProjectID = tblChangeItemDetail.
ProjectID)) ON Product.ProductDescription = tblChangeItemDetail.
ProductDescription) INNER JOIN tblChangeRequest ON (tblChangeRequest.
ChangeRequestID = tblChangeItem.ChangeRequestID) AND (tblChangeRequest.
ProjectID = tblChangeItem.ProjectID) AND (Project.ProjectID =
tblChangeRequest.ProjectID)

ORDER BY Project.ProjectID, tblChangeItem.RoomNumber & " - " & tblChangeItem.
ItemNumber;

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...eries/200702/1


 




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 02:21 PM.


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