> Thanks for your help!
> I've found some code at msdn and now my code is something like
> [code]
> strSQL = "SELECT emeter_code, datum, stand, verbruik FROM meterstand order
> by emeter_code, datum"
> Do While Not .EOF
There's no need to resorts to procedural code (Do While Not EOF) and
cursors (ORDER BY or Sort). A set-based SQL solution is possible.
Hopefully this simple (English language) example illustrates the point
CREATE TABLE Test (
key_col INTEGER NOT NULL,
date_col DATETIME NOT NULL,
data_col INTEGER NOT NULL);
INSERT INTO Test VALUES (1, #2001-01-01#, 1);
INSERT INTO Test VALUES (1, #2002-01-01#, 2);
INSERT INTO Test VALUES (1, #2003-01-01#, 3);
INSERT INTO Test VALUES (2, #2001-02-01#, 1);
INSERT INTO Test VALUES (3, #2001-03-01#, 1);
INSERT INTO Test VALUES (3, #2002-03-01#, 2);
SELECT T1.key_col, T1.date_col, T1.data_col,
(SELECT MAX(date_col) FROM Test
WHERE T1.key_col = key_col
AND date_col < T1.date_col) AS prev_date,
(SELECT T2.data_col FROM Test AS T2
WHERE T2.key_col = T1.key_col
AND T2.date_col =
(SELECT MAX(date_col) FROM Test
WHERE T1.key_col = key_col AND date_col < T1.date_col)
) AS prev_value FROM Test AS T1;