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  

Consolidate rows



 
 
Thread Tools Display Modes
  #1  
Old February 13th, 2007, 08:17 PM posted to microsoft.public.access.queries
BruceM
external usenet poster
 
Posts: 723
Default Consolidate rows

This is the SQL for a select (Totals) query that shows me the number of
parts per category that have been processed according to a particular
Technical Plan:

ProcName PartCat QtySum PartNum
----------- -------- -------- --------
Plate Gear 100 12345
Plate Gear 50 54321

This listing shows two jobs of 50 parts each (PartNum 12345) and one job of
50 parts of 54321. The two jobs for PartNum 12345 were consolidated into
one row. What I want is for all three jobs to be consolidated into one row
for Plating jobs on Gears:

ProcName PartCat QtySum
----------- -------- --------
Plate Gear 150

PartNum is in the first example for clarity. In practice I don't need the
PartNum to show, but whether it shows or not, the quantities are separated
as shown in the first example. How do I tell the query to sum the PartQty
for all of the Plate jobs on Gears? Here is the SQL:

SELECT tblProcess.ProcName, tblPart.PartCat,
DSum("[PartQty]","[tblJob]","[PartID_Job] = " & [PartID] & " AND
[PlanID_Job] = " & [PlanID])
AS QtySum, tblPart.PartNum
FROM tblPart
INNER JOIN ((tblTechPlan
INNER JOIN tblJob
ON tblTechPlan.PlanID = tblJob.PlanID_Job)
INNER JOIN (tblProcess
INNER JOIN tjctPlanProc
ON tblProcess.ProcessID = tjctPlanProc.ProcessID_PlanProc)
ON tblTechPlan.PlanID = tjctPlanProc.PlanID_PlanProc)
ON tblPart.PartID = tblJob.PartID_Job
GROUP BY tblProcess.ProcName, tblPart.PartCat,
DSum("[PartQty]","[tblJob]","[PartID_Job] = " & [PartID] & " AND
[PlanID_Job] = " & [PlanID]), tblPart.PartNum
ORDER BY tblProcess.ProcName, tblPart.PartCat;

I also tried making a query (qryCategory) from tblPart:

SELECT tblPart.PartID, tblPart.PartCat
FROM tblPart;

and substituting qryCategory.PartID and qryCategory.PartCat for
tblPart.PartID and tblPart.PartCat as needed, but still the same result
because the joining field (PartID) is different when the part numbers are
different.




  #2  
Old February 13th, 2007, 08:48 PM posted to microsoft.public.access.queries
BruceM
external usenet poster
 
Posts: 723
Default Consolidate rows

By the way, I can get the desired result by making a Select query from the
query I described in the original posting (I will call it qryCount):

SELECT qryCount.ProcName, qryCount.PartCat, Sum([QtySum]) AS QtyTotal
FROM qryCount
GROUP BY qryCount.ProcName, qryCount.PartCat;

It strikes me as clumsy to pile queries on top of each other like this, but
if it's an OK way to do it I'll move on to the next part of the project.

"BruceM" wrote in message
...
This is the SQL for a select (Totals) query that shows me the number of
parts per category that have been processed according to a particular
Technical Plan:

ProcName PartCat QtySum PartNum
----------- -------- -------- --------
Plate Gear 100 12345
Plate Gear 50 54321

This listing shows two jobs of 50 parts each (PartNum 12345) and one job
of 50 parts of 54321. The two jobs for PartNum 12345 were consolidated
into one row. What I want is for all three jobs to be consolidated into
one row for Plating jobs on Gears:

ProcName PartCat QtySum
----------- -------- --------
Plate Gear 150

PartNum is in the first example for clarity. In practice I don't need the
PartNum to show, but whether it shows or not, the quantities are separated
as shown in the first example. How do I tell the query to sum the PartQty
for all of the Plate jobs on Gears? Here is the SQL:

SELECT tblProcess.ProcName, tblPart.PartCat,
DSum("[PartQty]","[tblJob]","[PartID_Job] = " & [PartID] & " AND
[PlanID_Job] = " & [PlanID])
AS QtySum, tblPart.PartNum
FROM tblPart
INNER JOIN ((tblTechPlan
INNER JOIN tblJob
ON tblTechPlan.PlanID = tblJob.PlanID_Job)
INNER JOIN (tblProcess
INNER JOIN tjctPlanProc
ON tblProcess.ProcessID = tjctPlanProc.ProcessID_PlanProc)
ON tblTechPlan.PlanID = tjctPlanProc.PlanID_PlanProc)
ON tblPart.PartID = tblJob.PartID_Job
GROUP BY tblProcess.ProcName, tblPart.PartCat,
DSum("[PartQty]","[tblJob]","[PartID_Job] = " & [PartID] & " AND
[PlanID_Job] = " & [PlanID]), tblPart.PartNum
ORDER BY tblProcess.ProcName, tblPart.PartCat;

I also tried making a query (qryCategory) from tblPart:

SELECT tblPart.PartID, tblPart.PartCat
FROM tblPart;

and substituting qryCategory.PartID and qryCategory.PartCat for
tblPart.PartID and tblPart.PartCat as needed, but still the same result
because the joining field (PartID) is different when the part numbers are
different.






  #3  
Old February 13th, 2007, 09:21 PM posted to microsoft.public.access.queries
John Spencer
external usenet poster
 
Posts: 7,815
Default Consolidate rows

Would the following give you what you want.

SELECT tblProcess.ProcName
, tblPart.PartCat
, SUM (tblJob.PartQty) as QtySum
FROM tblPart
INNER JOIN ((tblTechPlan
INNER JOIN tblJob
ON tblTechPlan.PlanID = tblJob.PlanID_Job)
INNER JOIN (tblProcess
INNER JOIN tjctPlanProc
ON tblProcess.ProcessID = tjctPlanProc.ProcessID_PlanProc)
ON tblTechPlan.PlanID = tjctPlanProc.PlanID_PlanProc)
ON tblPart.PartID = tblJob.PartID_Job
GROUP BY tblProcess.ProcName, tblPart.PartCat
ORDER BY tblProcess.ProcName, tblPart.PartCat

--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..

"BruceM" wrote in message
...
This is the SQL for a select (Totals) query that shows me the number of
parts per category that have been processed according to a particular
Technical Plan:

ProcName PartCat QtySum PartNum
----------- -------- -------- --------
Plate Gear 100 12345
Plate Gear 50 54321

This listing shows two jobs of 50 parts each (PartNum 12345) and one job
of 50 parts of 54321. The two jobs for PartNum 12345 were consolidated
into one row. What I want is for all three jobs to be consolidated into
one row for Plating jobs on Gears:

ProcName PartCat QtySum
----------- -------- --------
Plate Gear 150

PartNum is in the first example for clarity. In practice I don't need the
PartNum to show, but whether it shows or not, the quantities are separated
as shown in the first example. How do I tell the query to sum the PartQty
for all of the Plate jobs on Gears? Here is the SQL:

SELECT tblProcess.ProcName, tblPart.PartCat,
DSum("[PartQty]","[tblJob]","[PartID_Job] = " & [PartID] & " AND
[PlanID_Job] = " & [PlanID])
AS QtySum, tblPart.PartNum
FROM tblPart
INNER JOIN ((tblTechPlan
INNER JOIN tblJob
ON tblTechPlan.PlanID = tblJob.PlanID_Job)
INNER JOIN (tblProcess
INNER JOIN tjctPlanProc
ON tblProcess.ProcessID = tjctPlanProc.ProcessID_PlanProc)
ON tblTechPlan.PlanID = tjctPlanProc.PlanID_PlanProc)
ON tblPart.PartID = tblJob.PartID_Job
GROUP BY tblProcess.ProcName, tblPart.PartCat,
DSum("[PartQty]","[tblJob]","[PartID_Job] = " & [PartID] & " AND
[PlanID_Job] = " & [PlanID]), tblPart.PartNum
ORDER BY tblProcess.ProcName, tblPart.PartCat;

I also tried making a query (qryCategory) from tblPart:

SELECT tblPart.PartID, tblPart.PartCat
FROM tblPart;

and substituting qryCategory.PartID and qryCategory.PartCat for
tblPart.PartID and tblPart.PartCat as needed, but still the same result
because the joining field (PartID) is different when the part numbers are
different.






  #4  
Old February 14th, 2007, 12:22 PM posted to microsoft.public.access.queries
BruceM
external usenet poster
 
Posts: 723
Default Consolidate rows

Yes, thank you, that did it exactly. Curiously, in my workaround I used Sum
instead of DSum, but for some reason I was stuck on DSum in the original
query. I think I understand that Sum is the sum of the number field
(PartQty) for all records that fall within the group, so grouping by QtySum
is not necessary (nor is it possible when Sum is used rather than DSum).
Like so many things, it's pretty clear once I see it.

"John Spencer" wrote in message
...
Would the following give you what you want.

SELECT tblProcess.ProcName
, tblPart.PartCat
, SUM (tblJob.PartQty) as QtySum
FROM tblPart
INNER JOIN ((tblTechPlan
INNER JOIN tblJob
ON tblTechPlan.PlanID = tblJob.PlanID_Job)
INNER JOIN (tblProcess
INNER JOIN tjctPlanProc
ON tblProcess.ProcessID = tjctPlanProc.ProcessID_PlanProc)
ON tblTechPlan.PlanID = tjctPlanProc.PlanID_PlanProc)
ON tblPart.PartID = tblJob.PartID_Job
GROUP BY tblProcess.ProcName, tblPart.PartCat
ORDER BY tblProcess.ProcName, tblPart.PartCat

--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
.

"BruceM" wrote in message
...
This is the SQL for a select (Totals) query that shows me the number of
parts per category that have been processed according to a particular
Technical Plan:

ProcName PartCat QtySum PartNum
----------- -------- -------- --------
Plate Gear 100 12345
Plate Gear 50 54321

This listing shows two jobs of 50 parts each (PartNum 12345) and one job
of 50 parts of 54321. The two jobs for PartNum 12345 were consolidated
into one row. What I want is for all three jobs to be consolidated into
one row for Plating jobs on Gears:

ProcName PartCat QtySum
----------- -------- --------
Plate Gear 150

PartNum is in the first example for clarity. In practice I don't need
the PartNum to show, but whether it shows or not, the quantities are
separated as shown in the first example. How do I tell the query to sum
the PartQty for all of the Plate jobs on Gears? Here is the SQL:

SELECT tblProcess.ProcName, tblPart.PartCat,
DSum("[PartQty]","[tblJob]","[PartID_Job] = " & [PartID] & " AND
[PlanID_Job] = " & [PlanID])
AS QtySum, tblPart.PartNum
FROM tblPart
INNER JOIN ((tblTechPlan
INNER JOIN tblJob
ON tblTechPlan.PlanID = tblJob.PlanID_Job)
INNER JOIN (tblProcess
INNER JOIN tjctPlanProc
ON tblProcess.ProcessID = tjctPlanProc.ProcessID_PlanProc)
ON tblTechPlan.PlanID = tjctPlanProc.PlanID_PlanProc)
ON tblPart.PartID = tblJob.PartID_Job
GROUP BY tblProcess.ProcName, tblPart.PartCat,
DSum("[PartQty]","[tblJob]","[PartID_Job] = " & [PartID] & " AND
[PlanID_Job] = " & [PlanID]), tblPart.PartNum
ORDER BY tblProcess.ProcName, tblPart.PartCat;

I also tried making a query (qryCategory) from tblPart:

SELECT tblPart.PartID, tblPart.PartCat
FROM tblPart;

and substituting qryCategory.PartID and qryCategory.PartCat for
tblPart.PartID and tblPart.PartCat as needed, but still the same result
because the joining field (PartID) is different when the part numbers are
different.








 




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 10:04 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.