Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Increment Number Problem

Status
Not open for further replies.

Debbie37

Technical User
Feb 23, 2002
28
US
Hi, I am trying to get a row number for each record in a group using MD_ID and CreateDate (date/time). For some MD_ID groups it works and others it does not. Can anyone tell me what I am doing wrong? Thanks in advance!

SELECT A.MD_ID, A.CreateDate, Count(*) AS [DefCt]
FROM tblAll AS A INNER JOIN tblAll AS B ON A.MD_ID = B.MD_ID and A.CreateDate > B.CreateDate
GROUP BY A.MD_ID, A.CreateDate;

Results
The last colimn is the DefCt that increments...
MD_ID CreateDate DefCt
2161 06/01/2012 15:13:00 1
2161 06/04/2012 10:55:00 2
2161 06/04/2012 13:25:00 3
2161 06/04/2012 13:43:00 4
2161 06/04/2012 13:45:00 10
2161 06/06/2012 07:47:00 7
2161 06/06/2012 08:47:00 8
2161 06/06/2012 14:28:00 9
2161 06/06/2012 14:34:00 10
2161 06/06/2012 15:08:00 11
2179 02/02/2011 15:04:00 1
2179 02/02/2011 15:05:00 2
2179 02/09/2011 08:21:00 3
2179 02/09/2011 08:27:00 4
2179 07/01/2011 12:57:00 5
2179 07/06/2011 08:12:00 6
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top