Select Date, Code, Sum(Amount) as Total, (SELECT Sum(ord2.Amount) From Orders ord2 Where fk_Customer = 1 And Date Between '20020101' and '20021231' And ord2.date() <= orders.date() And ord2.code = orders.code) AS RunTotal From Orders Where fk_Customer = 1 And Date Between '20020101' and '20021231' Group by Code, Date Order by Code, DateI tested above query and it produces result you want.
>2002-01-22 00:00:00.000 Ru1 -2.00000 -2.0000 >2002-01-28 00:00:00.000 Ru1 -1.00000 -3.0000 >2002-04-06 00:00:00.000 Ru3 2.00000 -1.0000 >2002-04-24 00:00:00.000 Ru1 -2.00000 -3.0000 >2002-05-15 00:00:00.000 Ru1 1.00000 -2.0000 >2002-05-16 00:00:00.000 Ru1 -1.00000 -3.0000 >2002-08-06 00:00:00.000 Ru3 4.00000 1.0000>