Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Increment
Message
From
20/10/2011 08:49:51
 
 
To
20/10/2011 03:36:00
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows XP
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01526941
Message ID:
01526962
Views:
66
>Dear Experts
>
>Table1 has following Data
>
>
>S_NO -- CODE
>1------ 1102
>1------ 1102
>1------ 1103
>1------ 1104
>1------ 1201
>1------ 1202
>1------ 1203
>
>
>I want to replace s_no as below
>
>S_NO-- CODE
>1------ 1101
>1------ 1102
>1------ 1103
>1------ 1104
>2------ 1201
>2------ 1202
>2------ 1203
>
>sno column must increment with 1 where code column changes

I'll assume it's not as simple as in your example, where you can set S_NO to the second digit of Code. Assuming that's true and also assuming both fields are numeric, you'll need a loop:
LOCAL nCurrentSNo, nCurrentStartDigits

SELECT Table1
GO TOP IN Table1

nCurrentSNo = 1
nCurrentStartDigits = FLOOR(Code/100)

SCAN
   IF FLOOR(Code/100) <> m.nCurrentStartDigits
      nCurrentSNo = m.nCurrentSNo + 1
      nCurrentStartDigits = FLOOR(Code/100)
   ENDIF

   REPLACE SNo WITH m.nCurrentSNo
ENDSCAN
Untested, so make sure to back up your data before testing.

Tamar
Previous
Reply
Map
View

Click here to load this message in the networking platform