Querying All Active Employees Within The Current Year In Dynamics GP

A big part of my job involves pulling data out of the Dynamics GP database in order to meet the needs of various Human Resources and Accounting  reports.  Recently a request was made on behalf of the HR department to retrieve a list of all employees who were actively employed during the current year. In addition to providing the basic employee identification data, they also required certain demographic data as this was a report being provided to the government to meet  our yearly Affirmative Action reporting requirements.

Pulling this data out of Dynamics GP is actually quite simple.  Fortunately the data requested resides in a single location, the UPR00100 – Employee Master table.   However, due to the way certain data is stored in the database as well as the need to report on both active and inactive employees based on when they were terminated, some additional logic is required to allow for all data to be included and to simplify the data so that it can be easily understood.

The script shown below will handle this.  In this example I am creating two separate data sets and inserting them into separate temp tables (#A1 and #A2).

#A1 contains the data for all active employees while #A2 contains the data for all employees who are currently inactive but were active during the current year.

I have also included CASE statements to transform various integer values assigned to certain data elements into their true value so that the end user can better understand the data.  Data such as ethnic origin and gender are are stored in the database as integers.  Each integer represents a certain value that is typically only interpreted by the application.  By cross referencing the application values with the values in the database I was able to create the necessary logic to present the true value within the report.

As stated previously, the above script is designed to retrieve all active employees and any employees who were active during the current year.  In some cases it may be necessary to include employees who were active in previous years as well.  Should that be the case simply replace the initial DECLARE statement in the script with the one shown below and update the variable’s value with the desired year. This will allow the script to pull all employees who were active going back to that year.

The screenshot below illustrates the output when going back to the previous year.  In this example it shows both active and inactive employees.  Since the default value for the LASTDAYWORKED_I column in the Dynamics GP database is set to 1900-01-01 00:00:00.000 this value will be displayed for all employees who are currently active.  The REASON value will only be displayed for employees who are currently inactive.


Depending on your reporting needs it may be necessary to include additional information about each employee.  The UPR00100 table includes significantly more data than is currently being retrieved by the script.  Keep in mind that this table contains highly sensitive data and any reports created out of this table should be secured so that only the intended recipients can view the data.