Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
INDEX ON....IIF(x,'ASCENDING','DESCENDING')
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00350533
Message ID:
00350685
Views:
23
Fellow Texan,

Using IIF(VAL2 = "D", 1/(VAL(VAL1)+1), VAL1)I believe would only work for a configuration like the sample has where there are only two records maximum of either the "A" or "D" type in a row. In real life, however, there will be anywhere from 10 to a Maximum of maybe 100 to maybe even 200 of either Ascending or Descending records in a row.

I was thinking that if indexing didn't work then maybe SQL SELECT might but I'm not a wiz at SQL and can't think of a way to do this in SQL either.

If I can't use either INDEX or SQL then it seems that my only alternative would be to programmatically run down the "D" records when I see them and then, from the last one in that series, work my way back up with a SKIP -1 and then, when I have gone through all of the "D"s, run back down again until I find the next "A". This would really slow down things going through a really large table and I was hoping to figure out a way of indexing first which, even if it was a convoluted index, would be faster (I believe) than my programmatic approach.

Looking at the simplified sample table, though, I just can't get it out of my head that there has to be a way.

Thanks again.

Ed


>The closest I could get was either:
>
>INDEX ON IIF(VAL2 = "D", 1/(VAL(VAL1)+1), VAL1+VAL2) TAG Test1
>
>or
>
>INDEX ON IIF(VAL2 = "D", 1/(VAL(VAL1)+1), VAL1) TAG Test2
>
>Needless to say, I would betRushmore will be shot to hell on something like this.
>
>>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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform