Avatar of phman1275
phman1275
 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...
SQL

Avatar of undefined
Last Comment
phman1275

8/22/2022 - Mon
Ryan Chong

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.
smilieface

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.
phman1275

ASKER
I want the value calculated at the time of row creation.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
ASKER CERTIFIED SOLUTION
slightwv (䄆 Netminder)

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ste5an

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.
phman1275

ASKER
Thank you slightwv (䄆 Netminder).