Link to home
Start Free TrialLog in
Avatar of Phman Super
Phman SuperFlag for United States of America

asked on

SQL Table

Hi, I need to create a SQL Table "Employees" table with the following fields:

ID, Name, Hiredate, Seniority

123, Johm, 11/8/1984, ????

For the Seniority field: if the current date - hiredate < 1 then 'Newbie'

****************************************************
My question is, should I put the seniority field as a calculation field? Or should I use the trigger to determine the employee is 'Newbie', 'Junior', or 'Senior'?

I have no clue how to either use the calculation to calculate the Seniority or use the trigger to do that.. Please help...
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

I have no clue how to either use the calculation to calculate the Seniority or use the trigger to do that.. Please help...

it depends on your requirement. To make this easy, you can use a calculated field for Seniority in a View or in Stored Procedure. And you no need to physically store it as a different field.
As Ryan says, It depends. Do you want this value calculated at the time of row creation or row retrieval....

Assuming you want it at time of row CREATION then try a trigger

If you want it calculated at time of RETRIEVAL then use a calculated column / in a view etc.
Avatar of Phman Super

ASKER

I want the value calculated at the time of row creation.
ASKER CERTIFIED SOLUTION
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
My question is, should I put the seniority field as a calculation field? Or should I use the trigger to determine the employee is 'Newbie', 'Junior', or 'Senior'?
None of these, Cause it's a time depended state. Thus it's a separate table where you track the states over time per employee.
Furthermore, a seniority level without department or function is meaningless.

p.s. not all new employee's are hired as newbies.
Thank you slightwv (䄆 Netminder).