How to Index on Numbers in a Character FieldID: Q112839 2.50 2.50a 2.50b 3.00 | 1.02 2.00 2.50 2.50a 2.50b | 2.50b kbprg
The information in this article applies to:
SYMPTOMSIf a character field is made up of numbers and the database is indexed on this field, the numbers are not in the expected order. NOTE: This article assumes that all numbers must be positive.
CAUSEIn character fields, each character is evaluated one at a time from left to right. Therefore, the order may not match that of a numeric field.
RESOLUTIONTo get the character field in numerical order, you must create an index key using the PADL() function. The PADL() function will put a character to the left of the character expression in order to make the digits right aligned.
Example1. In your database, create a character field called IDNUM that has a width 2. In the Command window, type:
3. In the Command window, issue the following command in order to index the
The order of IDNUM will now emulate that of a numeric field.
MORE INFORMATIONTo illustrate the behavior described in the "Symptoms" section above, suppose you have a character field called IDNUM that has a width of 10 and is made up of all numbers. The following table shows how the numbers will be ordered.
The numbers that begin with "1" will come first, then the numbers that
begin with "2", and so on because the index expression is evaluated based
on one character at a time rather than on the whole numeric expression.
Additional reference words: VFoxWin 3.00 FoxMac FoxDos FoxWin 1.02 2.00 2.50 2.50a 2.50b KBCategory: kbprg KBSubcategory: FxprgGeneral
|
Last Reviewed: May 1, 1996 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |