Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I index on two fields?

Status
Not open for further replies.

rollypac

Programmer
Jun 13, 2003
23
0
0
US
I have a family # and an individual #. I need to index on both fields. The family is a character field with numbers so I am indexing on the value; the individual field is numeric.
my code looks like this for the family:
index on val(alltrim(familynum)) to 23idx

How do I add the individual?
 
First, the Alltrim() really isn't necessary - Val() logically will do this.

Normally when indexing on two fields you simply concatenate character fields - changing any numbers to strings. e.g.
Code:
INDEX on FamilyNum+STR(IndivNum,2) to FamIndiv
If you want to use a numeric index, then you'd have to scale the family value and add on the individual value. e.g.
Code:
INDEX on VAL(FamilyNum)*100+IndivNum to FamIndiv
In both these cases I'm assuming that the Individual Number is just 2 digits (0-99), you'd change the "2" in the first expression and the "100" in the second one to the appropriate values if you need a different scalling.

Rick

 
I was about to report a typo here and say that it should be "Tag" not "To":
Code:
Index on <expression> Tag <indexname>
Then I remembered that "To" creates an Idx file rather than a tag in a Cdx file. Are you still using Idx files in VFP?

Geoff Franklin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top