+ Reply to Thread
Results 1 to 2 of 2

Create a SQL to combine data from 3 different sources

  1. #1
    Registered User
    Join Date
    08-31-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    87

    Create a SQL to combine data from 3 different sources

    I would like to create a SQL for query that combines the data from 3 different tables/query..

    The query will group them based on the Employee ID.

    There are 3 tables and 1 query in this SQL.

    Table 1 is a list of Employee IDs.

    Table 2 has these fields:
    Employee ID
    Dept Name
    Dept Type
    Dept Group Dept Status
    Person's Name
    Person's Status
    Person's Region
    Account Number
    Commission Date
    Expenses Aug-12
    Expenses Sept-12
    Expenses Oct-12
    ....
    Last Field will always be named "Total of Expenses"


    Table 3 has these fields:
    Employee ID
    Last Name
    First Name
    Date
    Division
    Title
    Company
    Region
    Customers
    Bonus Plan
    ....
    Last field will always be named "Account String"



    Query will have these fields:
    Employee ID
    Currency
    SumOfSalary
    SumOfDebt
    SumOfDeferred
    ...
    Last field will always be named "SumOfTotal"



    I would like to create a "join properties" that would include all employee ids in Table 1 and include those records from the other tables where joined fields are equal...

    Then I would like to group them based on the employee ids in Table 1 and ONLY pull the data starting from those that are underlined above until the last field.

    So I would only like to pull data from "Commission Date" field until "Total of Expenses" field in Table 2

    I would only like to pull data from "Bonus Plan" field until "Account String" field in Table 3

    The names of the fields between "Commission Date" and "Total of Expenses" fields will vary... The number of fields between the 2 fields will also vary. This applies to Table 2 and the Query too..


    What will be the SQL of this?

    Thanks!

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Create a SQL to combine data from 3 different sources

    The way your tables are designed just isn't right.

    You shouldn't have multiple fields for Expenses, you should probably have an Expenses table.

    That table would have a field for the employee ID, a field for month/date and a field for expenses.

    It could be summarised with a simple totals query.

    Also, you wouldn't have a Total Expenses field, you would use a query to calculate that.

    If you keep the tables as there are you'll need to write lengthy SQL statements in which you specify exactly which fields to include.
    If posting code please use code tags, see here.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1