How to Index a Combined Date and Character Field

Last reviewed: April 29, 1996
Article ID: Q97066
The information in this article applies to:
  • Microsoft Visual FoxPro for Windows, version 3.0
  • Microsoft FoxBASE+ for the Macintosh, version 2.01
  • Microsoft FoxPro for MS-DOS, versions 2.0 and 2.5
  • Microsoft FoxPro for Windows, versions 2.0 and 2.5
  • Microsoft FoxPro for Macintosh, version 2.5

To create an index on combined Date and Character type fields, you must break the Date type field into separate year, month, and day components; use the STR() function to connect the date pieces in the correct order; and then add the Character type field to the date string.

You can use the following examples to create an index on combined Date and Character type fields (the INVOICES database is referenced in the examples):

   INDEX ON STR(YEAR(idate))+STR(MONTH(idate))+STR(DAY(idate))+cno TO
   "date_cno.idx"

   -or-

   INDEX ON DTOC(idate, 1)+cno TO "date_cno.idx"

   -or-

   INDEX ON DTOS(idate)+cno TO "date_cno.idx"

NOTE: The third example above applies ONLY to FoxPro versions 2.0 and later (including FoxPro for Macintosh), not to FoxBASE+.

REFERENCES

"Microsoft FoxBASE+ Commands & Functions," page 4-22 "Microsoft FoxPro Language Reference," version 2.5, page L3-473


Additional reference words: VFoxWin 3.00 FoxWin FoxDos FoxMac 2.00 2.01
2.50 index cross-
platform
KBCategory: kbprg
KBSubcategory: FxprgGeneral


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: April 29, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.