I would like suggestions how to solve the following demand.
I have a table with three fields: EmployeeId, HireDate and DepartmentId.
The EmployeeId needs to be in the following format: yyyyddddxxxx
where:
yyyy - is the year the employee was hired.
dddd - DepartmentId.
xxxx - running number for each department on each year.
Would this be best computed using sql or C#?
How do I calculate the ‘xxxx’ part?
I can add more fields to the table if needed.
Magic!
Will give us the following:
UPDATE:
Now supposing you want to add a new employee to the Department #2 today. Here’s how I’d calculate a new EmployeeCode for this employee:
UPDATE:
As you can see, if you add an employee to a hitherto nonexistent department, say, #200, then the max clause would return null as there are no employees in this department and it’d get isnulled to 0 + 1, so you’d get a perfectly normal
201002000001for that employee.Suppose a year passed and now it’s 2011 and this last filtering clause again would null the max clause and the procedure would repeat and we’d get
201102000001for a new employee in that new department this next-year.