Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can I add incremental counter in select statement
Message
 
To
19/11/2007 14:52:03
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01269984
Message ID:
01269999
Views:
14
>>>>Is there a way to add an incremental count expression while using SELECT statement. For example, the statement below retrieves record into cursor:
>>>>
>>>>
>>>>select firstname from sometable into cursor
>>>>
>>>>
>>>>the data retrieved is;
>>>>
>>>>john
>>>>susan
>>>>mary
>>>>etc..
>>>>
>>>>
>>>>Is there a way to write the SELECT statement where I can add a number for each record retrieved. For example:
>>>>
>>>>the desired data I would like to retreive is the firstname column and incremental number column (I don't know how to add something in SELECT statement to create incremental numbers);
>>>>
>>>>name column    incremental number column
>>>>john           1
>>>>susan          2
>>>>mary           3
>>>>etc..          etc..
>>>>
>>>>
>>>>is there anything I can add in the SELECT statment to get incremental number column. Thanks
>>>>
>>>>Nick
>>>
>>>I don't think so. But even if you could, I suggest that you do that in a second run.
>>>select firstname,00000 as counter from sometable into cursor readwrite
>>>replace all counter with recno()
>>
>>thanks for the suggestion Tore, couldn't escape the second run. Thanx again.
>>
>>Nick
>
>You're welcome. Please forgive my ignorance, but what do you mean by "couldn't escape the second run"?


After creating the cursor during select, I had to repopulate the column as you stated. Origianlly I was trying to populate second column while retrieving the records. In the original run, I did put RECNO() for second column, but the numbers didn't comeout in numerical order as need them too. Thanx again.

Nick
Previous
Reply
Map
View

Click here to load this message in the networking platform