Something like this would work. I'm sure you'll have to play with it.DECLARE @totals TABLE( ident INT IDENTITY(1,1) PRIMARY KEY, col1 CHAR(1), col2 CHAR(1), col3 INT)INSERT @totals(col1, col2, col3) SELECT 'A', 'a', 2 UNION ALL SELECT 'A', 'b', 5 UNION ALL SELECT 'A', 'c', 7 UNION ALL SELECT 'B', 'a', 3 UNION ALL SELECT 'B', 'c', 5 UNION ALL SELECT 'C', 'd', 5 UNION ALL SELECT 'C', 'f', 9SELECT t.ident, t.col1, t.col2, t.col3, (SELECT COUNT(col1) FROM @totals WHERE ident <= t.ident AND col1 = t.col1) AS RtotalFieldFROM @totals tGROUP BY t.col1, t.col2, t.col3, t.ident
MeanOldDBAderrickleggett@hotmail.comWhen life gives you a lemon, fire the DBA.