Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can I add incremental counter in select statement
Message
From
20/11/2007 02:42:44
 
 
To
19/11/2007 17:06:25
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:
01270090
Views:
20
>>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
>>
>
>If you were in VFP 9, you could do with a derived table:
>
>
>SELECT *, RECNO() AS nCounter ;
>  FROM (SELECT <your actual query>) RealData ;
>  INTO CURSOR NumberedResult
>
>
>Tamar

In practice this one liner does exactly the same as my two liner. VFP does the inner SQL first, equal to my first line. Then it adds the recno field, like my line number two. My guess is that the time it takes to run this query is pretty much the same as my two lines. And I will argue that my code is easier to write and read.
Previous
Reply
Map
View

Click here to load this message in the networking platform