Solved

How to do a summary of 7 tables

Posted on 2009-05-05
3
293 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MS SQL export CSV & schedule It 9 52
SQL Server R2 Stored procedure make faster 7 48
SQL Server 2008 R2 - Execution Plan 3 57
subtract 1 in Access 2003 query 7 39
'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

920 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now