Results 1 to 2 of 2
  1. #1
    compooper is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2011
    Posts
    87

    SQL For Complex Inner Join

    Hi folks,



    Can you help me write a complex SQL/VBA code to do the following:

    background:
    There are multiple companies, providing multiple services.
    I have taken the time to make a table that essentially has all service codes, descriptions for each company

    The table, lets call it tblMapping, looks something like this
    mappingID Autonumber
    CompanyID Number
    Svc_Code Text
    Svc_Description Text
    AccountID Number
    SvcID Number
    SvcPrice Number

    AccountID is the account a service belongs to. For example, hair cuts belongs to Salon Account

    SvcID is a generic name I came up with for common services between companies
    For example, CompanyA might have hair cuts and Company B might call it Hair-Cuts
    So SvcID says Hair-Cuts just to keep things simple

    SvcPrice is the quoted price by the company. So if anything is less/more, something is fishy and I should know.

    What I need to do:
    So the whole point of the tblmapping, is so I can keep things related.

    I want to develop a query that looks a really big table of invoices (tblInvoices) from all the companies

    It will use CompanyID (selected by a user) to filter through the data
    It will then take each service code & description and match it to the mapping
    Compare the prices and spit out any prices that are not equal to the mapping

    The difficulty I am having:

    Some companies have svc_codes that are blank & just a svc_description
    Some companies only svc_codes
    Some comapnies have both svc_codes and svc_description, but sometimes like to add a few words to their description like

    1198 Hair-cutes (This client had the softest hair)

    Some companies might add a service out of the blue and it won't be in my mapping
    And some companies are just awesome.

    I've tried writing numerous SQL statements with inner joins, but honestly its just not working.
    Any ideas?

  2. #2
    compooper is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2011
    Posts
    87
    This is sort of what I am trying to do:

    SELECT tblInvoices.CompanyID, tblInvoices.InvTypeID, tblInvoices.InvPeriod, tblInvoices.App_policynum, tblInvoices.App_lname, tblInvoices.App_fname, tblInvoices.Svc_code, tblInvoices.Svc_description, tblmapping.Svc_price
    FROM tblmapping INNER JOIN tblInvoices ON IIF(CompanyID=6, tblInvoices.Svc_code=tblmapping.Svc_code and tblInvoices.Svc_description=tblmapping.Svc_descrip tion, false) OR IIF(CompanyID=4, tblInvoices.Svc_code Is null AND tblInvoices.Svc_description=Svc_description, false) OR IIF(CompanyID=1 OR CompanyID=2 OR CompanyID=3 OR CompanyID=5 OR CompanyID=7, tblInvoices.Svc_code=tblmapping.Svc_code, false)
    ORDER BY tblInvoices.ID;

    But clearly it doesn't work.
    How do you run an IIF statement, and if its false go to the next IIF statement in SQL?

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Help with complex 'IF' function(s) ...
    By Captain Database ...!! in forum Queries
    Replies: 4
    Last Post: 06-13-2011, 12:40 PM
  2. Too Complex to be evaluated - HELP!
    By awmmoore in forum Queries
    Replies: 2
    Last Post: 06-06-2011, 10:23 AM
  3. Complex Criteria
    By Kapelluschsa in forum Queries
    Replies: 7
    Last Post: 05-23-2011, 03:45 PM
  4. need help, expression is too complex?
    By ice673 in forum Queries
    Replies: 5
    Last Post: 02-15-2010, 09:03 PM
  5. Complex Lookup?
    By murphyB in forum Database Design
    Replies: 1
    Last Post: 09-17-2009, 12:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums