Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Colleen2 is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2022
    Posts
    26

    access query if both order types match for employee

    trying to write a query to return "yay" or "Nay" if both attainment = yes for each Rep_Empid




  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    if Boolean field
    select * from table where [Attain1]=true and [Attain2]=true

    if text:
    select * from table where [Attain1]='yes' and [Attain2]='yes'

  3. #3
    Colleen2 is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2022
    Posts
    26
    this is in a query and that didn't work
    Sample:



  4. #4
    Colleen2 is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2022
    Posts
    26
    just returns 1 for those that are yes and 0 for no
    IIf([rep_empid],[attainment]='yes' And [attainment]='yes')
    Rep_EmpID SA_ID Sales Assignment Employee Name Order Type Attainment
    3477 SA01686 Reed,Lana L Digital No
    3477 SA01686 Reed,Lana L TotalRevenue YES
    5831 SA01068 Fields-Snyder,Terry Ann Digital YES
    5831 SA01068 Fields-Snyder,Terry Ann TotalRevenue No
    16300 SA00356 Jordan,Mary M Digital YES
    16300 SA00356 Jordan,Mary M TotalRevenue YES

  5. #5
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,407
    That little comma should be a period and use plain IF

    If ([rep_empid].[attainment]='yes' And [attainment]='yes')

    Would be helpful to see the complete query so context implications would be plainer.

  6. #6
    CarlettoFed is offline Competent Performer
    Windows 7 64bit Access 2013 32bit
    Join Date
    Dec 2019
    Posts
    255

    Response

    What you wrote does not make sense, it shows the Sql predicate of the query.

  7. #7
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,407
    Quote Originally Posted by CarlettoFed View Post
    What you wrote does not make sense, it shows the Sql predicate of the query.
    I think more clearly, your requirement is that you have a table with 2 records for an employee. You want a query to show the employees with 'Yes' in the attainment field for both records.

  8. #8
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,043
    create 2 subqueries: 1 selects the rep_empID, SA_ID, employee_name where order type = 'digital' and attainment = 'Yes'; the other one selects the rep_empID, SA_ID, employee_name where order type = 'TotalRevenue and attainment = 'Yes'.
    Join the 2 queries together on the field rep_empID (in T-SQL you use an OUTER APPLY for that, but I remember that Access SQL can differ from T-SQL) and the resulting recordset should only contain those employees where both attainment fields are true.

  9. #9
    Colleen2 is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2022
    Posts
    26
    that got me closer but for the ones that both = Yes should be Yay not Nay like Mary Jordan Click image for larger version. 

Name:	Query results.JPG 
Views:	12 
Size:	89.9 KB 
ID:	47047
    her is the statement Expr1: IIf([rep_empid].[attainment]='yes' And [attainment]='yes',"Yes","Nay")

  10. #10
    Colleen2 is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2022
    Posts
    26
    I don't want to remove any employees just identify the ones that have yes for both order types "Digital" and "TotalRevenue"

  11. #11
    Colleen2 is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2022
    Posts
    26
    Yes that is correct

  12. #12
    Colleen2 is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2022
    Posts
    26
    Yes that is correct I have a table with 2 records for an employee. I want a query to show the employees with 'Yes' in the attainment field for both records

  13. #13
    CarlettoFed is offline Competent Performer
    Windows 7 64bit Access 2013 32bit
    Join Date
    Dec 2019
    Posts
    255
    When asking questions you need to be clear from the start.
    Assuming that the table, where the data you exposed in post # 4 is,
    Rep_EmpID SA_ID Sales Assignment Employee Name Order Type Attainment
    3477 SA01686 Reed,Lana L Digital No
    3477 SA01686 Reed,Lana L TotalRevenue YES
    5831 SA01068 Fields-Snyder,Terry Ann Digital YES
    5831 SA01068 Fields-Snyder,Terry Ann TotalRevenue No
    16300 SA00356 Jordan,Mary M Digital YES
    16300 SA00356 Jordan,Mary M TotalRevenue YES
    is called Rep_Emps the query is the following:
    Code:
    SELECT Rep_Emps.*, IIf([CountOfRep_EmpID]=1,"Nay","Yes") AS Outcome
    FROM Rep_Emps INNER JOIN (SELECT Rep_Emps.Rep_EmpID, Count(Rep_Emps.Rep_EmpID) AS CountOfRep_EmpID
    FROM Rep_Emps
    WHERE (((Rep_Emps.[Order Type])="Digital" Or (Rep_Emps.[Order Type])="TotalRevenue") AND ((Rep_Emps.Attainment)="yes"))
    GROUP BY Rep_Emps.Rep_EmpID) AS SearchData
     ON Rep_Emps.Rep_EmpID = SearchData.Rep_EmpID;
    and the result is the following
    Rep_EmpID SA_ID Sales Assignment Employee Name Order Type Attainment Outcome
    3477 SA01686 Reed,Lana L Digital No Nay
    3477 SA01686 Reed,Lana L TotalRevenue YES Nay
    5831 SA01068 Fields-Snyder,Terry Ann Digital YES Nay
    5831 SA01068 Fields-Snyder,Terry Ann TotalRevenue No Nay
    16300 SA00356 Jordan,Mary M Digital YES Yes
    16300 SA00356 Jordan,Mary M TotalRevenue YES Yes

  14. #14
    Colleen2 is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2022
    Posts
    26
    I apologize for not being clear from the start. Yes this is exactly what I wanted. How do I put it in an expression?

  15. #15
    Colleen2 is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2022
    Posts
    26
    I figured it out! thank you all for helping me.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 08-12-2019, 12:39 PM
  2. Replies: 1
    Last Post: 12-22-2014, 11:47 AM
  3. Replies: 1
    Last Post: 07-31-2014, 10:13 PM
  4. Set Employee On Call Order and Rotate
    By burrina in forum Access
    Replies: 2
    Last Post: 10-23-2012, 10:14 AM

Tags for this Thread

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