Forum Discussion

DataComplianceNerd's avatar
DataComplianceNerd
Copper Contributor
Jan 28, 2020
Solved

Finding Multiple Values

I have a table that has thousands of rows in it. I need to write a query to pull out lines where a person is serving more than one function.   Below in my example I want Micky below to appear in my q...
  • George_Hepworth's avatar
    George_Hepworth
    Jan 30, 2020

    George_Hepworth 

     

    Based on this sample data, these queries return three employee IDs with 2 (or more) Function Codes within the range of the data. To apply date range filtering, you can join this query back to the payroll data and filter it on date.

     

    SELECT Payrolldata.ID, Payrolldata.FunctionCode
    FROM Payrolldata
    GROUP BY Payrolldata.ID, Payrolldata.FunctionCode;

     

    Save this as UniqueEmployeeFunctionCodes

     

    Use it in this query.

     

    SELECT UniqueEmployeeFunctionCodes.ID, Count(UniqueEmployeeFunctionCodes.FunctionCode) AS MultipleFunctionCodes
    FROM UniqueEmployeeFunctionCodes
    GROUP BY UniqueEmployeeFunctionCodes.ID
    HAVING (((Count(UniqueEmployeeFunctionCodes.FunctionCode))>1));

     

     

Resources