Alerts Based on EMP_ID

Rarely can we create a Workbrain Alert without joining database tables in SQL. When we want to send the alert based on an an employee, we must select EMP_ID in the SQL, the EMP_ID has to be selected first, and as of now in the software, the column name has to be strictly EMP_ID. Not doing this and selecting an option that requires EMP_ID, the Workbrain application will throw the following error:

EMP_ID must be one of the columns if recipient roles are populated or self is checked

We cannot only return an aliased EMP_ID, which you may do if you are selecting the EMP_ID from an alternate column, such as an EMP_VAL. Nor can we only return E.EMP_ID, which could be the case if you aliased the EMPLOYEE table as E. The Workbrain hack in this case is to surround your entire query with a select * from ().

For example, if I want to write Oracle SQL to send an alert to supervisors for all employees that have birthdays today in the system, then I could use the following:

select E.EMP_ID, E.EMP_FULLNAME from EMPLOYEE E where to_char(E.EMP_BIRTH_DATE, 'DD-MM') = to_char(sysdate, 'DD-MM')

In order to used this as an alert in Workbrain, I would need to make the SQL look like this:

select * from (select E.EMP_ID, E.EMP_FULLNAME from EMPLOYEE E where to_char(E.EMP_BIRTH_DATE, 'DD-MM') = to_char(sysdate, 'DD-MM'))

This is a simplified case without SQL JOINs; we could have just removed the alias E and it would have worked just fine, but I'm sure you get the idea.

0 comments:

Post a Comment