This is how you do it. You also need to brush up your math skills regarding percentual changes.-- prepare test datadeclare @t table (Payment_point varchar(5), Payment_type varchar(4), [month] datetime, amount smallint)set dateformat dmyinsert @tselect 'AA000', 'FLAG', '1/04/2006', 110 union allselect 'AA000', 'FLAG', '1/05/2006', 100 union allselect 'AA000', 'FLAG', '1/06/2006', 100 union allselect 'AA000', 'FLAG', '1/07/2006', 110 union allselect 'AA000', 'US', '1/01/2005', 600 union allselect 'AA000', 'US', '1/02/2005', 300 union allselect 'AA000', 'BON', '1/03/2005', 20 union allselect 'AA000', 'BON', '1/04/2005', 30-- do the workselect t.Payment_point, t.Payment_type, t.[month], t.amount, CASE WHEN v.amount IS NULL THEN 'No previous month' else str(100.0 * (t.[amount] - v.[amount]) / v.[amount], 17, 2) end '%_change_prev_month'from @t tleft join @t v on v.payment_point = t.payment_point and v.payment_type = t.payment_type and year(v.[month]) = year(t.[month]) and month(v.[month]) = month(t.[month]) - 1order by t.Payment_point, t.Payment_type, t.[month]
Peter LarssonHelsingborg, Sweden