Results 1 to 11 of 11
  1. #1
    Nushan is offline Novice
    Windows 10 Access 2016
    Join Date
    Dec 2019
    Posts
    7

    Need help to create a query between 2 table

    Hi guys.



    Please help me to create a query between 2 tables. I am new to Access.

    Table 1 : CB_Data (from Branch)
    Table 2 : CB_Payment_Info (Country Duty Paid Data)

    I need to verify whether "code_2" product charges already paid by country or not. tried IIF function,it doesn't work

    IIF( [CB_Data]![Code_2] = [CB_Payment_Info]![Code_2] ,"Paid","Pending") .


    Thanks in Advance.

  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    Add both tables to your query. Add a join to link both tables by the Code_2 fields.
    Add the fields you require to the query and filter the Code_2 field value = "Paid"
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  3. #3
    Nushan is offline Novice
    Windows 10 Access 2016
    Join Date
    Dec 2019
    Posts
    7
    Is it the same way to bring "Paid" & "Pending" like in excel if statement???

  4. #4
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    Excel and Access are very different in terms of analysing data.
    Do you want to see individual records showing whether Paid or Pending?
    Or do you want a count of the number of Paid records and the number Pending?
    Or something else?
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  5. #5
    Nushan is offline Novice
    Windows 10 Access 2016
    Join Date
    Dec 2019
    Posts
    7
    Yes, I need to know whether individual record was paid or not. If i include "status"(Paid/Pending) in CB_Payment_Data & link to CB_Data and use IIF function like " IIF( [CB_Data]![Code_2] ="Paid","Paid","Pending") ", will it work???

  6. #6
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    Do what I wrote in post #2 without the filter.
    You can certainly use an IIf function to display an extra field but of course that field won't be stored in your table (and probably shouldn't be)

    However I'm not sure whether you need that extra field at all.
    It would help me to help you if you posted a few records of example data (modify if anything is confidential) together with the expected output
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  7. #7
    Nushan is offline Novice
    Windows 10 Access 2016
    Join Date
    Dec 2019
    Posts
    7
    I have attached the file. Thank you..
    Attached Files Attached Files

  8. #8
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    You also need to tell me what the expected output would be with that data
    You have 6 records in all, 5 records in the PaymentInfo table and 3 in the other table (one not in the PaymentInfo table).
    There are 2 records with the same data in both tables.
    How many of the records and what results do you want in your query?

    However, why are you duplicating data in the two tables?
    Doing that goes against database design principles. Data should be stored once only.

    Both your tables have the same structure but with an extra field in the PaymentInfo table.
    Why not just use one table?

    Also neither table has a primary key field. This is a basic table requirement.
    Will ProductID be unique? If so make that the PK.
    Otherwise add a new autonumber field as the primary key.

    Before you go any further I strongly recommend that you spend some time researching the basics of database table design including the idea of normalising data. After that read up about queries.
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  9. #9
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,529
    Here is your SQL statement for your current design. However, Colin makes very good sense.

    Code:
    SELECT CB_Data.[Product ID], CB_Data.Code2, CB_Data.[Duty Charges], CB_Payment_Info.[Duty Charges], CB_Payment_Info.BPV, IIf([CB_Data]![Duty Charges]=[CB_Payment_Info]![Duty Charges],"Paid","Pending") AS Status
    FROM CB_Data INNER JOIN CB_Payment_Info ON CB_Data.[Product ID] = CB_Payment_Info.[Product ID];
    Attached is a good read on data base design
    Attached Files Attached Files

  10. #10
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    Hi Alan
    Thanks for joining in to assist

    For the benefit of the OP and referring to the records as mentioned earlier, using an INNER JOIN will give the 2 common records. Left or right outer joins will give 3 or 5 records and a union query (full outer join) will give all 6 records.

    If all of that means nothing to you, it reinforces the point about learning database basics
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  11. #11
    Nushan is offline Novice
    Windows 10 Access 2016
    Join Date
    Dec 2019
    Posts
    7
    Thank you for your help and advice guys. I just started to learn Access, and i don't understand sql statement yet. I will close the thread.. again thanks for your help.

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

Similar Threads

  1. Replies: 3
    Last Post: 09-24-2019, 12:22 AM
  2. create query from table
    By adaoluz in forum Queries
    Replies: 2
    Last Post: 11-06-2018, 07:34 PM
  3. How do I get the CREATE TABLE part from a table creation query?
    By Javier Hernández in forum Programming
    Replies: 5
    Last Post: 01-14-2014, 01:56 PM
  4. Replies: 2
    Last Post: 12-20-2011, 07:33 AM
  5. Replies: 1
    Last Post: 12-16-2011, 08:16 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