Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Replace sno with a sequence
Message
 
To
05/06/2005 23:44:40
General information
Forum:
Visual FoxPro
Category:
Other
Environment versions
Visual FoxPro:
VFP 6
OS:
Windows '98
Network:
Windows 98
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01020377
Message ID:
01021236
Views:
21
CREATE TABLE table1 ;
 (sno n(3))

INSERT INTO table1  (sno) VALUES (9)
INSERT INTO table1  (sno) VALUES (7)
INSERT INTO table1  (sno) VALUES (4)
INSERT INTO table1  (sno) VALUES (3)
INSERT INTO table1  (sno) VALUES (9)
INSERT INTO table1  (sno) VALUES (8)
INSERT INTO table1  (sno) VALUES (6)
INSERT INTO table1  (sno) VALUES (5)
INSERT INTO table1  (sno) VALUES (9)
INSERT INTO table1  (sno) VALUES (1)
INSERT INTO table1  (sno) VALUES (2)

SELECT Table1
m.Oldsno = -99 && Or any other number you sure not in table
DIMENSION aPassedNo[1,2]
STORE 0 TO aPassedNo, m.add_passed, m.replSerNo
*SET STEP ON
SCAN
   IF m.Oldsno # sno
      cSerNo = PADL(ALLTRIM(STR(sno)),7,"0")
      nAsc   = ASCAN(aPassedNo,cSerNo)
      IF nAsc == 0
         m.add_passed = m.add_passed + 1
         m.replSerNo  = m.add_passed
         DIMENSION aPassedNo[m.add_passed,2]
         aPassedNo[m.add_passed,1] = cSerNo
         aPassedNo[m.add_passed,2] = m.Newsno
      ELSE
         nAsc        = ASUBSCRIPT(aPassedNo,nAsc,1)
         m.replSerNo = aPassedNo[nAsc,2]
      ENDIF
      m.Oldsno    = sno
   ENDIF
   REPLACE sno WITH m.replSerNo
ENDSCAN

brow
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Reply
Map
View

Click here to load this message in the networking platform