Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Index on multiple columns (fields)
Message
From
23/07/2003 10:10:22
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
 
 
To
23/07/2003 00:32:22
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00812633
Message ID:
00812767
Views:
23
>Hi,
>
>Gr8 it works fine.
>One more question (I becoming little greedy here), now similar to a date field I have a Charchater and a numeric field. How do I sort these to fields.
>charachter field is CustName and Numeric field is OrderAmt, both the field values are same for all items under one order.

If all fields are ascending, it is easy to convert everything to character, and concatenate.

For instance:
index on CharacterField + str(NumericField)

index on CharacterField + bintoc(NumericField)

index on CharacterField + str(NumericField, 10, 2) && if you have 2 decimals
For descending numbers, you could use something like str(-NumericField) or bintoc(-NumericField) or str(-NumericField, 10, 2).

If you want to have character descending and numeric ascending, it is easierto do this the other way: character ascending, numeric descending, and then use the index in reverse order.

HTH,

Hilmar.



>
>Thanks again,
>
>regards
>Shaishav
>
>>How to do it, I explained in my other reply.
>>
>>But what you actually do would depend on the purpose.
>>
>>If you show the information in a grid, as part of an editing form, you might need the index.
>>
>>If it is for a report, the SELECT - SQL solution is easier. Everything you SELECT goes to a cursor, a temporary table, that is deleted automatically as soon as you close it.
>>
>>>Dear Hilmar,
>>>
>>>Thanks for your reply;
>>>
>>>Actually I want to sort fields in one table; can I sort one field on descending and other on ascending??
>>>
>>>Actually what I want is;
>>>
>>>I have a ItemsOrdered table; this table has the data in following format;
>>>
>>>OrederNo ItemCode(Primary Key) ItemNo ItemDate ItemQty
>>>20030101 20030101-001 001 01/01/2003 15000
>>>20030101 20030101-002 002 01/01/2003 30000
>>>20030101 20030101-002 003 01/01/2003 45000
>>>
>>>20030301 20030301-001 001 01/03/2003 15000
>>>20030301 20030301-002 002 01/03/2003 25000
>>>20030301 20030301-003 003 01/03/2003 35000
>>>
>>>Please note that the First 8 letters of ItemCode represents OrderNo.
>>>Last 3 digits represents ItemNo.
>>>And also note that the ItemDate for each item within a OrderNo is same.
>>>
>>>If user wants to see ItemOrdered data in desc order of ItemDate:
>>>It should display in desc order of ItemDate but maintaining the sequence of ItemNo, that means it should show as follows;
>>>
>>>OrederNo ItemCode(Primary Key) ItemNo ItemDate ItemQty
>>>20030301 20030301-001 001 01/03/2003 15000
>>>20030301 20030301-002 002 01/03/2003 25000
>>>20030301 20030301-002 003 01/03/2003 35000
>>>
>>>20030101 20030101-001 001 01/01/2003 15000
>>>20030101 20030101-002 002 01/01/2003 30000
>>>20030101 20030101-003 003 01/01/2003 45000
>>>
>>>I don't want to use SELECT-SQL statement for this, because the information is available in a table. Can I define any Index tag to achieve this??
>>>
>>>TIA
>>>
>>>Shaishav
>>>
>>>>It can be done, but what do you need this index for? If you use indices are to ensure uniqueness of data, for referential integrity, or to search, it doesn't matter whether the index is ascending or descending (therefore, use an ascending index).
>>>>
>>>>If it is for a report, just use SELECT - SQL, with the ORDER BY clause. Here, you can explicitly use ASCENDING and DESCENDING for individual fields, and you don't need to concatenate everything into a single expression.
>>>>
>>>>>Hi Everyone,
>>>>>
>>>>>I want to index my table on two columns (item_code + item_date). I want to index in such way that,
>>>>>
>>>>>Item_date is sorted in descending order and item code is sorted on ascending order.
>>>>>
>>>>>E.g.
>>>>>Item_code Item_date
>>>>>========= =========
>>>>>Item1 01/01/2003
>>>>>Item2 01/01/2003
>>>>>Item3 01/01/2003
>>>>>Item1 01/04/2003
>>>>>item2 01/04/2003
>>>>>item3 01/04/2003
>>>>>
>>>>>The above should be displayed as;
>>>>>Item_code Item_date
>>>>>========= =========
>>>>>Item1 01/04/2003
>>>>>Item2 01/04/2003
>>>>>Item3 01/04/2003
>>>>>Item1 01/01/2003
>>>>>item2 01/01/2003
>>>>>item3 01/01/2003
>>>>>
>>>>>Any suggestions???
>>>>>
>>>>>Cheers
>>>>>Shaishav
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
Reply
Map
View

Click here to load this message in the networking platform