Solved

How to do a summary of 7 tables

Posted on 2009-05-05
3
305 Views
Last Modified: 2012-05-06
I am trying to figure out a way of trying to get a summary of 7 tables in order to add certain fields like a check amount, deductions etc.  Can this be possible?  Please let me know.  Thanks!
0
Comment
Question by:VBBRett
3 Comments
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 24308200
What do you mean by summary?  Please give slight examples of the data in the 7 tables and what you expect results to be or at least explain further.
0
 

Author Comment

by:VBBRett
ID: 24319892
A summary meaning I want certain fields to be added mathematically to get a sum of certain fields.  Basically it's a payroll system I am trying to add up the deductions, the the pay codes, taxes, etc.
Below is an example of a record:

Record-Type  Company  Empid   PLevel  Dept  Checkid  Paycode  DedCode  Hours Wage-amt Ded-amt
      1                 2525        1234     2392              12521      205                          8        20              10
       1                2525        1234     2392               12521                   TAX           8                           5

So basically there are 7 tables like this.  I would like to add things like the hours, the wage-amt, the ded-amt, etc.  There are more fields then what I showed but I just wanted to get a general idea.  What I am trying to do is take each paycheck pay period information table and combine them and add them all up to be a quarterly data table.

Does that make sense?
0
 
LVL 40

Accepted Solution

by:
Sharath earned 500 total points
ID: 24320764

You need to know the JOIN condition(s) or JOIN column(s) to JOIN your tables.
After you JOIN all the tables, you may end up with a query like this.
SELECT Record-Type, Company, Empid, PLevel,  Dept,  Checkid,  Paycode,  DedCode,  Hours, [Wage-amt],[Ded-amt],
       <and all other columns from your other tables>
  FROM Table1
 INNER JOIN Table2 ON <JOIN condition>
 INNER JOIN Table3 ON <JOIN condition>
 INNER JOIN Table4 ON <JOIN condition>
 INNER JOIN Table5 ON <JOIN condition>
 INNER JOIN Table6 ON <JOIN condition>
 INNER JOIN Table7 ON <JOIN condition>
Now if you want to add certain fields, you can simply add those fields with +.

SELECT Record-Type, Company, Empid, PLevel,  Dept,  Checkid,  Paycode,  DedCode,  Hours, [Wage-amt],[Ded-amt],
       [Wage-amt] + [Ded-amt] AS Wage_Ded_Amt
  FROM Table1
 INNER JOIN Table2 ON <JOIN condition>
 INNER JOIN Table3 ON <JOIN condition>
 INNER JOIN Table4 ON <JOIN condition>
 INNER JOIN Table5 ON <JOIN condition>
 INNER JOIN Table6 ON <JOIN condition>
 INNER JOIN Table7 ON <JOIN condition>
Hope you got how to implement this.
If you still looking for assistance, provide the field names which you want to add and the JOIN conditions between your tables.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Add different cell to otherwise similiar row 4 39
export sql results to csv 6 36
string fuctions 4 26
SQL Server 2012 r2 - Varible Table 3 27
In database programming, custom sort order seems to be necessary quite often, at least in my experience and time here at EE. Within the realm of custom sorting is the sorting of numbers and text independently (i.e., treating the numbers as number…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question