torturedmind
Programmer
Hi all. I just wanted to share a small tip I found from databasejournal by Gregory A. Larsen. This is based on SQL Server so I modified it a bit to suit my needs coz am (still) using VFP6
. This will sequentially number the records where each group starts numbering from 1 to N, where N is the number of records in the group, and then starts over again from 1, when the next group is encountered.
The outcome is something like this:
I hope this will also help someone in need. It sure did help me. Credits to Mr. Gregory A. Larsen for the original code.
kilroy![[knight] [knight] [knight]](/data/assets/smilies/knight.gif)
philippines
"Once a king, always a king. But being a knight is more than enough."
![[hairpull2] [hairpull2] [hairpull2]](/data/assets/smilies/hairpull2.gif)
Code:
SELECT COUNT(*) AS itemno, ;
mytable2.grpcode, ;
mytable2.membrcode ;
FROM mytable AS mytable2 ;
INNER JOIN mytable AS mytable3 ;
ON mytable2.membrcode >= mytable3.membrcode ;
AND mytable2.grpcode = mytable3.grpcode ;
INTO CURSOR mytable4 ;
GROUP BY mytable2.grpcode, mytable2.grpcode
SELECT mytable.grpcode, ;
itemno, ;
mytable.membrcode, ;
mytable.somenumbr ;
FROM mytable ;
INNER JOIN mytable4 ;
ON mytable.grpcode = mytable4.grpcode ;
AND mytable.membrcode = mytable4.membrcode ;
ORDER BY mytable.grpcode, mytable.membrcode
Code:
grpcode itemno membrcode somenumbr
======= ====== ========= =========
001-000 1 070A01 3845
001-000 2 070A02 548
001-001 1 070A03 6599
002-001 1 070A04 2411
002-001 2 070B01 687
002-001 3 070B03 511
002-001 4 070C05 3247
002-003 1 070B02 91
002-004 1 070C01 508
002-004 2 070C02 4461
002-004 3 070C03 514
002-005 1 070C04 6115
: : : :
: : : :
: : : :
kilroy
![[knight] [knight] [knight]](/data/assets/smilies/knight.gif)
philippines
"Once a king, always a king. But being a knight is more than enough."