Results 1 to 7 of 7
  1. #1
    boheili is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2014
    Posts
    4

    return results for those matching to either column A or B

    Hi,

    I have a report (contains sales#, order# and sales rep. name) and a sales list (contains sales#) this month. I am trying to write a query to present the sales rep. names with sales in the month. However, the sales# column in the sales list mixed with order# and sales#:

    Sales List:
    Column A - 111, bbb

    Report:
    Column A - 111, 222
    Column B - aaa, bbb
    Column C - John, Karl

    May I ask, how to join the column A in the sales list to both Column A & B in the report, to return column C?


    Really appreciate it!!!
    Last edited by boheili; 12-14-2014 at 08:11 AM. Reason: Adding example to my question

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Why don't you use the actual field names in your posted question?

    What do you mean by 'mixed with'? I don't understand the data as represented. Sales List shows 111, bbb in same field but the report shows them in separate fields - how does that happen?

    You have a table of sales reps? Is there a field in Sales List table with the reps ID?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    boheili is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2014
    Posts
    4
    Thanks for your reply, June7.

    Let me tell you a little bit more about the background.

    1. ORDER# is assigned when an order is initialized in the system; a unique SALES# will be assigned to the ORDER# when the product is delivered.

    2. The sales list is an excel file maintained by our operation team manually, to track the sales of the month. For the SALES# field in the file, it's supposed to contain only SALES#. However, our operation team sometimes put order# instead... So we will see that the SALES# field is actually a "mix" of ORDER# and SALES#...

    3. The report mentioned above is a report exported from the system. It contains SALES#, ORDER# and sales rep. name. They are well separated in fields as they are supposed to be.

    4. Here's the elaboration of the situation and my question:


    Sales List:
    SALES#/ORDER# - 111, bbb
    Sales amount - $10, $20

    Report:
    SALES# - 111, 222, 333
    ORDER# - aaa, bbb, ccc
    Sales rep. name - John, Karl, Marry

    In simple words, I try to write a query to search for ORDER# and sales rep. name based on the SALES#/ORDER# in the sales list. The results should look like this:
    SALES#/ORDER# - 111, bbb
    ORDER# - aaa, bbb
    Sales rep. name - John, Karl
    Sales amount - $10, $20

    As an Access date base newbie, I really don't know how to express this "conditional match" logic. Really appreciate it if anyone could help!




    Quote Originally Posted by June7 View Post
    Why don't you use the actual field names in your posted question?

    What do you mean by 'mixed with'? I don't understand the data as represented. Sales List shows 111, bbb in same field but the report shows them in separate fields - how does that happen?

    You have a table of sales reps? Is there a field in Sales List table with the reps ID?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    How would a Sales# be distinguished from Order#?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    boheili is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2014
    Posts
    4
    In real life, the ORDER# is a 13-digit combination; the SALES# is a 7-digit combination. Is it possible to distinguish the #s by matching them with the fields in the report? Like, 1) returning the report.order# by matching saleslist.sales#/order# to report.sales# field, 2) if null, then by matching to report.order# field.

    I am comfortable to express this logic in EXCEL, but don't know how to write them in SQL:

    =index(report.order#, iferror(match(saleslist.sales#/order#,report.sales#,0),match(saleslist.sales#/order#,report.order#,0)), 1)

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    A query can calculate the Order# and Sales# into separate columns.

    SELECT IIf(Len([SALES#/ORDER#])=13, [SALES#/ORDER#], Null) AS OrderNum, IIf(Len([SALES#/ORDER#])=7, [SALES#/ORDER#], Null) AS SalesNum, [Sales Amount] FROM [Sales List];

    But I don't think that will get you where you want.

    A UNION query can combine the Sales# and Order# fields of the Report table into one field.

    SELECT [Sales#] AS Sales_Order_Num, [Sales Rep], [Sales Amount] FROM Report
    UNION SELECT [Order#], [Sales Rep], [Sales Amount] FROM Report;

    Now build another query that joins the UNION to the Sales List table.



    BTW, advise no spaces or special characters/punctuation (underscore is exception) in naming convention.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    boheili is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2014
    Posts
    4
    Thank you, June7! Got your logic. That's really helpful!

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

Similar Threads

  1. Replies: 8
    Last Post: 07-10-2014, 09:44 AM
  2. return column number by VBA
    By ice051505 in forum Programming
    Replies: 4
    Last Post: 02-25-2013, 01:48 PM
  3. Report Data Not Matching Query Results
    By Rawb in forum Reports
    Replies: 7
    Last Post: 10-25-2012, 01:41 PM
  4. Replies: 7
    Last Post: 08-13-2010, 02:57 PM
  5. Replies: 1
    Last Post: 04-15-2010, 02:07 AM

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