• You might be able to use the Quirky update[/url] or the LEAD/LAG functions available on 2012.

    However, I did this using an islands solution that might fit your problem.

    WITH Groups AS(

    SELECT EMP_ID,

    Title,

    DateValue,

    TITLE_YEAR,

    DATEADD(YYYY, - ROW_NUMBER() OVER (PARTITION BY EMP_ID, Title ORDER BY DateValue), DateValue) Grouper

    FROM #mytable

    ), Added AS(

    SELECT EMP_ID,

    Title,

    DateValue,

    TITLE_YEAR,

    ROW_NUMBER() OVER (PARTITION BY EMP_ID, Title, Grouper ORDER BY DateValue) Years

    FROM Groups

    )

    UPDATE Added SET

    TITLE_YEAR = Years

    SELECT * FROM #mytable

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2