• I'm missig the CTE/Recursive approaches to solving these issues. While usually not single pass the beat triangular joins

    For Running total see: http://shahamishm.blogspot.com/2009/04/how-to-do-running-sum-using-cte-sql.html

    For finding previous row ordered by key_nr and trans_date(clustered key):

    WITH trans_cte(key_nr, trans_date,field1,field2,row_order)

    AS(

    SELECT

    key_nr

    ,trans_date

    ,field1

    ,field2

    ,ROW_NUMBER()OVER(PARTITIONBY key_nr ORDERBY trans_date ASC) row_order

    FROM [dbo].[trans_stage_table]

    )

    SELECT BASE.key_nr

    ,BASE.trans_date

    ,BASE.field1

    ,BASE.field2

    FROM trans_cte BASE

    LEFTJOIN trans_cte LAG ON BASE.key_nr = LAG.key_nr

    AND BASE.row_order = LAG.row_order+1

    and BASE.field1 = LAG.field1

    and BASE.field2 = LAG.field2

    where LAG.key_nr isnull

    Kind Regards,

    DM Unseen AKA M. Evers