• rn is the "rn" column from the cte which is the row number partitioned by staff_id, ordered by transaction_Date
    What version of SQL are you using?  I ran the above on one of my SQL 2008 boxes and it ran without any errors.

    I did realize that you will want to change the join to:
    FULL OUTER JOIN cte cte2 ON [cte1].[rn] = [cte2].[rn] + 1 AND [cte1].[Staff_id] = [cte2].[Staff_id]

    As you will want staff ID to be part of your join predicate otherwise you will end up with incorrect results if you have more than 1 staff ID.
    But I wrote the above query using your table name so it should just work.  You should be able to copy and paste the query exactly as is and run it without any problems.

    The above is all just my opinion on what you should do. 
    As with all advice you find on a random internet forum - you shouldn't blindly follow it.  Always test on a test server to see if there is negative side effects before making changes to live!
    I recommend you NEVER run "random code" you found online on any system you care about UNLESS you understand and can verify the code OR you don't care if the code trashes your system.