Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Nasty index, any better ideas?
Message
From
06/08/2003 17:14:48
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00817470
Message ID:
00817477
Views:
22
>I have a data field of mixed alphanumeric that needs a specific sort order. I think this is enough points to illustrate. They are either all integer data points, or begin with an alpha and the rest is numeric. Example:
>
>Unordered data: B16,16,C2,5,123,2,C21,D86,278,27,2796,B1,C22
>
>Ordered data: 2,5,16,27,123,278,2796,B1,B16,C2,C21,C22,D86
>
>Here's my quickly devised ordering method, call the field CatNumber (yeah, I know, yuck, this is not very elegant):
>
>INDEX ON IIF(ISALPHA(SUBSTR(CatNumber,1,1)),;
>1000*ASC(SUBSTR(CatNumber,1,1))+VAL(SUBSTR(CatNumber,2)),;
>VAL(SUBSTR(CatNumber,1))) TAG CatNumber
>
>The "1000" multiplier is big enough for all possible data points, BTW. It works, if a bit ugly, so why the problem? I'm doing a hobby-article for not very deep coders - people that have only MS Access available, IOW. And I don't find Access supporting the above solution. Anyone see any ideas that are simpler, and might work in Access? Just a "simpler vfp index" would be a good start for the Access stage...
>
>(Note: I'm avoiding any possible less-standard vfp functions like LEFT, also, as part of this project.)

I don't have VFP at hand to test the following, so you might try it.
index on str(val(CatNumber)) + CatNumber tag CatNumber
Reasoning:

val() should give 0 for codes that start with a letter. In this case, the second part should resolve ties.

HTH,

Hilmar.
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform