Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Increment Field
Message
From
11/04/2008 15:04:52
 
 
To
11/04/2008 13:44:43
Jay Johengen
Altamahaw-Ossipee, North Carolina, United States
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Environment versions
Visual FoxPro:
VFP 9 SP2
Miscellaneous
Thread ID:
01309981
Message ID:
01310012
Views:
29
This message has been marked as the solution to the initial question of the thread.
>>>Is there a way to have a value that increments by one in a SQL statement?
>>>
>>>
>>>SELECT *, IncrementThisValueByOne FROM MyTable
>>>
>>>
>>>To get:
>>>
>>>
>>>MyFieldOne MyFieldTwo IncrementThisValueByOne
>>>
>>>Bobby      Jones      1
>>>Jamie      Lee        2
>>>Terry      Hatcher    3
>>>
>>
>>If you're creating a VFP cursor, then you effectively get a RECNO() column without needing to have any sort of "IncrementThisValueByOne" column. Can you not just use that?
>
>No, it doesn't always start with 1 for each cursor.

Hmm, set-oriented SQL is not always the best choice for row-oriented logic like this. You might be better off sticking with xBASE:
m.lnOffset = < some integer value >

SELECT ;
  MyColumnOne ;
  , MyColumnTwo ;
  , CAST( 0 AS I ) AS IncColumn ;
  ...
  INTO CURSOR Output ;
  ORDER BY ... ;
  NOFILTER READWRITE

SELECT Output
REPLACE ALL ;
  IncColumn WITH RECNO( "Output" ) + m.lnOffset ;
  IN Output
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform