Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Summing data from multiple tables 1

Status
Not open for further replies.

agorjest

Technical User
Oct 23, 2007
51
US
Hello,
If anyone can help me with this I'd appreciate it:

Using CR 9, creating a report that tracks mechanical service workorders and totals their costs in terms of labor and parts/materials. It will draw data from 3 data tables: Workorders, Labor Transactions, and Materials Transactions. All 3 tables can be linked on a common field (Workorder #) that contains a 5 digit string that serves as the workorder ID number. There can be anywhere from 1 to hundreds of labor transactions for each workorder number, but for that same workorder there may only be 1 or 2 materials transactions. The problem I have is that CR pulls the records for each labor transaction and if there is only 1 materials transaction, that value will be repeated for each record. Here is how the records are displaying:

Group Name: WO # 10009
Details:
WO # Worker LaborDate LbrHours LbrRate LbrCost Mat.cost

10009 J.Smith 8/1/09 2.00 $10.00 $20.00 $100.00
10009 M.Jones 8/2/09 1.00 $10.00 $10.00 $100.00*

Group Name: WO # 10100
Details:
10100 B.Lee 8/4/09 0.50 $12.00 $6.00 $50.00
10100 M.Wilson 8/6/09 3.00 $15.00 $45.00 $50.00*
10100 M.Jones 8/7/09 1.00 $10.00 $10.00 $50.00*

Where you see the asterisks* are where the values are repeating where I don't want them to repeat. There should just be one value for Materials Costs, so when the Materials Costs are summed, it will total $100 for the first group and $50.00 for the 2nd group.
Note, the WO# field is taken from the Workorder table, the Materials Cost field is taken from the Materials Transactions table, and all the other fields are taken from the Labor Transactions table.

I've tried tinkering with linking the tables, changing around groups, and doing variable formulas, with no luck. It is always going to print each labor transaction record (as it should, since each record contains labor hours that need to be summed). But the material transactions are usually a one time transaction, and it's the cost of that one value that needs to be summed for each workorder. But the repeated values in the Materials Cost field are being added to the summed total, so I need to find a way to suppress them or prevent them from displaying and being included in the summed totals. Any ideas?
 
LB,
Here is the command I'm using:

SELECT 'LabTrans' "Table", "labtrans"."startdate" "transdate", "labtrans"."regularhrs", null "matlinecost", "workorder"."wonum", "workorder"."wo14", "workorder"."status"
FROM ("CMG"."dbo"."workorder" "workorder" INNER JOIN
"CMG"."dbo"."labtrans" "labtrans" ON "workorder"."wonum"="labtrans"."wonum")
WHERE "labtrans"."startdate">={?Start Date} AND
"labtrans"."startdate"<{?End Date} + 1
UNION ALL
SELECT 'Matusetrans' "Table", "matusetrans"."actualdate", null,
"matusetrans"."linecost","workorder"."wonum", "workorder"."wo14", "workorder"."status"
FROM ("CMG"."dbo"."workorder" "workorder" INNER JOIN "CMG"."dbo"."matusetrans" "matusetrans" ON "workorder"."wonum"="matusetrans"."wonum")
WHERE "matusetrans"."actualdate">={?Start Date} AND "matusetrans"."actualdate"<{?End Date} + 1

I want to calculate the percentage of a GL account's cost (group 2) to the total cost of all the GL accounts from a site (group 1). Since the running totals for the site occur in GF1 (after the RTs for the GL accounts in GF2), wouldn't I need a subreport in GH1 to give me the site's total cost $ figure in order to calculate a GL account's % against that site total?
If there'a a way around it, that would be great, because the sub-report slows down the report every time it re-queries and I'd rather do without it.

Thanks again...
 
The command should be your entire datasource. I don't see a field that corresponds to site or GL Accounts.

-LB
 
Sorry, I should have clarified: workorder.wo14 serves as the GL account field (it is Command.wo14 after the merger). The site is actually a formula field (@site) which uses Select/Case to determine the site based on the GL account. So in the @site formula, Command.wo14 (GL Account) is the "Select", with each "Case" being a string containing a GL account number, each one then assigned a 3 letter string (FTW, MAD, WAV) as it's site.
Example:
Select Command.wo14
Case "103101": "FTW"
Case "104202": "MAD"
Case "102103": "WAV"
etc...

So how would I get the total cost value from the group 2 (command.wo14, aka "GL Account") footer to divide into the total cost value in the Group 1 (@site) footer, with the the result appearing on the Group 2 footer line?
 
But I don't know what contributes to the total cost. Instead of using running totals, use formulas like this:

sum(costs,glacct)%sum(costs,site)

-LB
 
LB,
I scrapped the sub-report and went with the sums. Worked like a charm. I'm definitely on the SQL command bandwagon now. Makes things alot easier when working with multiple tables. Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top