Results 1 to 9 of 9
  1. #1
    bwhalen1 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2013
    Posts
    5

    Join with multiple Conditions - Passthrough Query

    Hey there,



    Created code in SQL server, I need to deliver these queries in Access SQL or to my end users- Just having a little trouble getting it converted over: Here is what I created in SQL (which works great)-

    Code:
    USE *********
    SELECT SS.DatePromised
    , SS.Customername
    , SS.CustomerNum
    , ID.MfgCode
    , ID.CatNum
    , ID.ProductDescription
    , ID.Price
    , ID.PriceUOM
    , SS.OrigRegNum
    , SS.CustPO
    , PO.PONum
    , ID.OrderQty
    , PO.PORecdQTY1
    , PO.PORecdDate1
    , PO.PORecdQTY2
    , PO.PORecdDate2
    , PO.PORecdQTY3
    , PO.PORecdDate3
    , ID.SalesType
    , SS.SalesRepNumIN
    , SS.SalesRepNumOUT
    FROM (dbo.OpenInvoiceDetail AS ID INNER JOIN dbo.openSalesSummary AS SS ON ID.OpenSalesSummaryID = SS.OpenSalesSummaryID)
    LEFT JOIN dbo.PODetail AS PO ON SS.OrigRegNum = PO.BOCustRegNum1 AND ID.CatNum = PO.CatNum
    WHERE SS.DatePromised < getdate()
    ORDER BY ID.OpenSalesSummaryID, Id.InvLine;

    Now I know in access its a little different - I was told that I need to use pass through queries - So I took a stab at it...

    pass through query
    Code:
    SELECT SS.DatePromised, SS.Customername, SS.CustomerNum, ID.MfgCode, ID.CatNum, ID.ProductDescription, ID.Price, ID.PriceUOM, Cint(SS.OrigRegNum) AS OrigRegNum, SS.CustPO, ID.OrderQty, ID.SalesType, SS.SalesRepNumIN, SS.SalesRepNumOUT
    FROM OpenInvoiceDetail AS ID INNER JOIN openSalesSummary AS SS ON ID.OpenSalesSummaryID = SS.OpenSalesSummaryID;

    Then I referred to it with this query:

    Code:
    SELECT openinvoicesub.*, PODetail.PONum, PODetail.PORecdQty1, PODetail.PORecdDate1, PODetail.PORecdQty2, PODetail.PORecdDate2, PODetail.PORecdQty3, PODetail.PORecdDate3
    FROM openinvoicesub LEFT JOIN PODetail ON (openinvoicesub.CatNum = PODetail.CatNum) AND (openinvoicesub.OrigRegNum = PODetail.BOCustRegNum1)
    WHERE openinvoicesub.DatePromised < [Date];
    Now I am getting the error "This expression is typed incorrectly, or is too complex to be evaluated..."

    Any guidance here would be greatly appreciated, as I have already spent waaay too much time tooling with access to get it to work. If only I could just use SQL server : /

    Thanks in advance!

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Well, a passthrough query would be passed through to SQL Server, so the T-SQL syntax would work fine (in fact it would have to be T-SQL). Does it need to be an Access query?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    bwhalen1 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2013
    Posts
    5
    Unfortunately Yes - Our end users have to be able to run this query with Access on their machines - As a preference I prefer to work in SQL, so Ill create it on my end and import it into their Access for them. Still learning - this task has just been a bit challenging. Basically just want to get that first SQL query in an Access friendly format, and was playing with different ideas.

    Like your title btw - just picked up Atlas Shrugged again the other day :P

  4. #4
    bwhalen1 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2013
    Posts
    5
    [edit ]

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    The only thing I see wrong in the last SQL is the brackets around Date, which would make Access think it was a field, but I would expect that to throw a parameter prompt. The fields in the joins are of compatible data types?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    bwhalen1 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2013
    Posts
    5
    Right on the Brackets - I did that so that it would throw the parameter prompt - The DBAs who designed the DB made a mistake and in my second query the

    PODetail.CatNum is actually of type number (says access) and SS.OrigRegNum from the frist query is actually a text ( says access) so thats why i cast it as type int "Cint(SS.OrigRegNum)"
    so when I compared them in query 2 "ON (openinvoicesub.CatNum = PODetail.CatNum)" it wouldn't throw an error. It was before I did that.

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I thought that was a pass through query? CInt() isn't valid in T-SQL, so that must just be an Access query. Is it possible that text field is Null in a record? That would cause the CInt() to error, and perhaps cause this problem when Access tries to evaluate the joined fields.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    bwhalen1 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2013
    Posts
    5
    Ohh you were right about the cInt what I did instead was use the Val function so it looks like:


    Val(SS.OrigRegNum) AS OrigRegNum

    in the first query - The types matched and no errors - results match my SQL Server query!


    Thank You for your troubleshooting help!

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No problem, and welcome to the site by the way!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Cannot Make Table with Passthrough Query
    By chasemhi in forum Import/Export Data
    Replies: 0
    Last Post: 12-05-2011, 01:30 PM
  2. Replies: 6
    Last Post: 02-13-2011, 06:02 PM
  3. Update Query - Multiple SETS and WHERE conditions
    By jasonbarnes in forum Queries
    Replies: 26
    Last Post: 12-15-2010, 01:08 PM
  4. Edit Query Data with multiple JOIN
    By Bruce in forum Queries
    Replies: 7
    Last Post: 07-08-2010, 05:20 PM
  5. Replies: 5
    Last Post: 06-19-2010, 07:55 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