SQL Queries Used When Setting Up Time Categories

When you set up a time category for timesheets in Time Settings, you can use SQL queries to define the project, phase, task, labor code, or labor category for a time category if you want these entries to differ by employee.

You enter a SQL query in the Project Query, Phase Query, Task Query, Labor Code Query, or Labor Category Query fields to determine the employee-specific entry that prefills for the time category on a timesheet.

Commonly used variables for these SQL queries are:

  • :emp
  • :wbs1
  • :wbs2
  • :wbs3
  • :laborcode
  • :activecompany (Multicompany)

Multiple Companies and Time Categories for Timesheets

If you use multiple companies, you must configure time categories on the Time Categories form for each company in Time Settings. For timesheet-related queries, it is important to note that an employee may be associated with more than one company. For this reason, queries that reference a company-specific field (such as Organization) should use the EMAllCompany view to search all the companies associated with the employee, and then use the :activecompany variable to look at the company-specific record for the timesheet's active company.

For example, to select the correct WBS2 for an employee who is associated with more than one company and is entering a timesheet, you need to know all of the company records for that employee, as well as which company record matches the active company for the timesheet.

SELECT WBS2 FROM PR INNER JOIN EMAllCompany ON LEFT(EMAllCompany.Org.2) = LEFT(PR.Org.2) WHERE PR.WBS1 = 'SPECIAL' AND EMAllCompany Employee = :emp AND EMAllCompany.EmployeeCompany = :activecompany AND PR.WBS2 <> ' '