Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2013
    Posts
    2

    Unanswered: Help with mixing outer and inner joins

    Hello,

    I'm a very novice SQL user and I am looking for some help. I am importing some data into Excel 2013 with Microsoft Query and as usual the query will not let me use and outer join with multiple table. Here is the complete SQL language I am getting. The text in red is what I need converted into an outer join where everything in BTTicketHdr.cnum is returned and only those matching in CUSTFIL2.CNUM are returned.

    SELECT BTTicketHdr.BatchNumber, CUSTFIL2.CNAME1, BTTicketHdr.cnum, BTTicketHdr.PNUM, PRODFIL2.PNAME1, PRODFIL2.MEAS, PRODFIL2.UM, PRODFIL2.UP, PRODFIL2.WGT, PRODFIL2.DIV, PRODFIL2.PCLASS, BTReceiptHdr.Yield, BTReceiptHdr.YieldUM, BTReceiptHdr.CompletionDate, BTReceiptHdr.Status, BTReceiptHdr.WHS, BTReceiptHdr.PM, BTReceiptHdr.PY, PostingPeriod.FiscalMonthStartDate

    FROM `X:\chempax.mdb`.BTReceiptHdr BTReceiptHdr, `X:\chempax.mdb`.BTTicketHdr BTTicketHdr, `X:\chempax.mdb`.CUSTFIL2 CUSTFIL2, `X:\chempax.mdb`.PostingPeriod PostingPeriod, `X:\chempax.mdb`.PRODFIL2 PRODFIL2

    WHERE BTReceiptHdr.BatchNumber = BTTicketHdr.BatchNumber AND BTTicketHdr.cnum = CUSTFIL2.CNUM AND BTTicketHdr.PNUM = PRODFIL2.PNUM AND BTReceiptHdr.PM = PostingPeriod.PM AND BTReceiptHdr.PY = PostingPeriod.PY

    ORDER BY BTTicketHdr.BatchNumber

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Why not create a new query within chempax.mdb with the appropriate joins and then link directly to that?
    George
    Home | Blog

  3. #3
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    You problem is actually in Jet SQL, the language used by Microsoft Access. I'll move your question to the Microsoft Access forum where it ought to get more attention and more useful answers.

    The following is "air code", I haven't tested it but it ought to work:
    Code:
    SELECT BTTicketHdr.BatchNumber, CUSTFIL2.CNAME1, BTTicketHdr.cnum
    ,  BTTicketHdr.PNUM, PRODFIL2.PNAME1, PRODFIL2.MEAS
    ,  PRODFIL2.UM, PRODFIL2.UP, PRODFIL2.WGT
    ,  PRODFIL2.DIV, PRODFIL2.PCLASS, BTReceiptHdr.Yield
    ,  BTReceiptHdr.YieldUM, BTReceiptHdr.CompletionDate, BTReceiptHdr.Status
    ,  BTReceiptHdr.WHS, BTReceiptHdr.PM, BTReceiptHdr.PY
    ,  PostingPeriod.FiscalMonthStartDate
       FROM `X:\chempax.mdb`.BTReceiptHdr BTReceiptHdr
       INNER JOIN `X:\chempax.mdb`.BTTicketHdr BTTicketHdr
          ON (BTReceiptHdr.BatchNumber = BTTicketHdr.BatchNumber)
       INNER JOIN `X:\chempax.mdb`.CUSTFIL2 CUSTFIL2
          ON (BTTicketHdr.cnum = CUSTFIL2.CNUM)
       INNER JOIN `X:\chempax.mdb`.PRODFIL2 PRODFIL2
          ON (BTTicketHdr.PNUM = PRODFIL2.PNUM)
       LEFT  JOIN `X:\chempax.mdb`.PostingPeriod PostingPeriod
          ON (BTReceiptHdr.PM = PostingPeriod.PM
    	  AND BTReceiptHdr.PY = PostingPeriod.PY)
       ORDER BY BTTicketHdr.BatchNumber
    I used the SQL-92 syntax for the JOIN operations, since it makes the intent clearer and unambiguous.

    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  4. #4
    Join Date
    Jun 2013
    Posts
    2
    I wish I could alter the source but I am only allowed to extract from the database. I cannot alter the source database.

  5. #5
    Join Date
    Feb 2004
    Location
    New Zealand
    Posts
    1,418
    Provided Answers: 7
    What i would try to do is link the said table in a new db them write the query

    One of my jobs they had a as400 i created a odbc link link the tables them i run the query over that
    hope this help

    See clear as mud


    StePhan McKillen
    the aim is store once, not store multiple times
    Remember... Optimize 'til you die!
    Progaming environment:
    Access based on my own environment: DAO3.6/A97/A2000/A2003/A2007/A2010
    VB based on my own environment: vb6 sp5
    ASP based on my own environment: 5.6
    VB-NET based on my own environment started 2007
    SQL-2005 based on my own environment started 2008
    MYLE
    YOUR PASSWORD IS JUST LIKE YOUR TOOTHBRUSH DON'T SHARE IT.

Posting Permissions

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