August 18, 2008 at 7:46 am
Hi! I need help with the calculation of average employee tenure. I have something like this:-
SELECT start_dates.Effectivedatepayroll, headcountdec.StaffNo, headcountdec.CallName, headcountdec.Surname,
DATEDIFF(yy, CONVERT(datetime, start_dates.Effectivedatepayroll), GETDATE()) AS Tenure
FROM start_dates INNER JOIN
headcountdec ON start_dates.staffno = headcountdec.StaffNo
Where Headcountdec.Period = 200807
with this I get the number of years a person has worked for the company but what I actually need is is average tenure.
Please Help
August 18, 2008 at 7:56 am
What is the grouping for which you wish to return average tenure?
It looks your query is returning per-person data, do you need average tenure in addition to this data or instead of this data? For the instead of you could do this:
[font="Courier New"]SELECT
AVG(DATEDIFF(YY, CONVERT(DATETIME, START_DATES.EFFECTIVEDATEPAYROLL), GETDATE())) AS AVG_TENURE
FROM
START_DATES INNER JOIN
HEADCOUNTDEC ON
START_DATES.STAFFNO = HEADCOUNTDEC.STAFFNO
WHERE
HEADCOUNTDEC.PERIOD = 200807 [/font]
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
August 18, 2008 at 8:06 am
Thanks a lot.
That was helpfull, I was looking for the average tenure for each branch not individuals.
Thanks again
August 18, 2008 at 8:10 am
Well, which column is the branch? Just modify my query to add the branch to the output and then add a group by branch.
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
August 18, 2008 at 8:15 am
I did and its working fine.
Thanks
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply