views:

22

answers:

1

For query data like this:

Name , Details

JEFF , TEST1

JEFF , TEST2

JEFF , TEST3

BOB , TEST1

BOB , TEST2

How do I query so that a numerical sequence (1,2,3...) can be added that resets back to 1 each time the name changes (ie from JEFF to BOB)?

Is it possible to use the DCOUNT function?

What I have so far is (it doesn't sequence correctly):

Number: (SELECT COUNT(*) FROM  [dQuery] 
WHERE  [dQuery].[Name] =  [dQuery].[Name] 
AND  [dQuery].[sequence] >=  [dQuery].[sequence])

UPDATE1:

The correct query is:

SELECT [dQuery].Name, [dQuery].[sequence], (select count([dQuery].Name) + 1 
from [dQuery] as dupe where 
dupe.[sequence]< [dQuery].[sequence] and dupe.name  = [dQuery].name
) AS [Corrected Sequence]
FROM [dQuery]
WHERE ((([dQuery].Name)="jeff"))
ORDER BY [dQuery].Name, [dQuery].[sequence];
+1  A: 

Take a look here. I think the author has solved some very similar issues.

Grembo