Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
INDEX ON....IIF(x,'ASCENDING','DESCENDING')
Message
De
26/03/2000 20:15:26
 
 
À
26/03/2000 20:10:59
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00350533
Message ID:
00350583
Vues:
22
>>>I'm trying to create an index that will internally change back and forth between Ascending and Descending depending on the value of a field.
>>>
>>>Let's say I have a table with the following fields and values.
>>>
>>>cValue AorD
>>>01 A
>>>02 A
>>>03 D
>>>04 D
>>>05 A
>>>06 A
>>>07 D
>>>08 D
>>>
>>>I want to index on cValue Descending but internally cValue would be subIndexed as either Ascending or Descending depending on the value of AorD so that the final index would produce the following result.
>>>
>>>cValue AorD
>>>01 A
>>>02 A
>>>04 D
>>>03 D
>>>05 A
>>>06 A
>>>08 D
>>>07 D
>>>
>>>Can anyone think of a way to do this even using UDFs if needed?
>>>
>>>Ed
>>
>>Maybe you could have all your "D" type records be negative values (at least for your index)?
>
>The problem here is that there's a segment of the key missing to indicate that the range '01' - '02' precedes the range '04'-'03' and is followed by the rnage '05'-'08'; the basis of the key is misdefined. Without the implicit key ordering the ranges, it's not doable. The key structure needs to be restated. the basis needs to be that there is a group, members of the first group must logically precede members of the second group; within that group, members of the group are arranged in either ascending or descending order.
>
>As long as the first level grouping exists, the ordering of the subgroup can be accomplished by logical inversion of the second key segment, if necessary by application of some form of key negation (a UDF that XORs the second key segment portion if that subgroup is descending rather than anscending, using a character-style key concatenation for presentation.)
>
>Solution - rethink the keys to define the appropriate grouping so that the real ordering key is based on a consistent order, with inversion of values within subsegments of the key. The real ordering key is consistently ascending, the full key value is in part formed by a logical operation on the data elements that go into building the key structure.


You are indeed correct and provided a much more thorough answer than mine. I didn't even notice that his proposed keyfield was a character field! But the principle is still the same, you need to have the main index in a "natural" order.
Fred
Microsoft Visual FoxPro MVP

foxcentral.net
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform