Re: Ordering records

From: Ray Chance <rchance_at_netcom.com>
Date: Thu, 4 Nov 1993 15:26:41 GMT
Message-ID: <rchanceCFz48I.Ksq_at_netcom.com>


Jeroen Hermans (b09_at_nikhef.nl) wrote:
: Hello everybody,
 

: I have a problem with ordering records. When I insert records they are
: shown in order by the order of inserting them into the database. Now I
: give each record a seperate following-up-number so that they will be
: ordered by that number. When I want to insert a record between existing

(stuff deleted) You shouldn't worry about the order the records are stored; if you need them sequentially, then assign the sequence number you mentioned above and then always select them with an "order by" clause. If you want to automatically re-sequence subsequent records, then if you're on V7, you'll need a database trigger based on the insert statement. If you're not on V7, then you'll need to execute the trigger manually. You might assign an ordering value such as '0100' incrementing by 100 initially (so the next row would be '0200'. Then you could derive the next row value such as '0110' and that should obviate the need for re-sequencing the subsequent rows. We do this but using 4 decimal places, and derive the next sequential number as the difference between previous and next divided by 10 added to the previous for the new row value.

Prev = 100
Next = 200

New = Prev + ( (Next - Prev) / 10 )

       100 + ( ( 200 - 100 ) / 10 )

       100 + ( 100 / 10 )

       100 + 10

New = 110 Received on Thu Nov 04 1993 - 16:26:41 CET

Original text of this message