Difference Between COPY TO ARRAY and SELECT INTO ARRAY

Last reviewed: April 29, 1996
Article ID: Q104053
The information in this article applies to:
  • Microsoft Visual FoxPro for Windows, version 3.0
  • Microsoft FoxPro for Windows, versions 2.5 and 2.5a
  • Microsoft FoxPro for MS-DOS, versions 2.0, 2.5, and 2.5a

SUMMARY

Once an array has been created with the COPY TO ARRAY command, the array length remains constant even when a subsequent COPY TO ARRAY command is issued. However, the SQL SELECT INTO ARRAY command creates a new array each time it is issued.

MORE INFORMATION

The following steps illustrate this behavior using the FoxPro 2.x CUSTOMER table:

  1. In the Command window, issue the following commands:

          SET DEFAULT TO <path to FoxPro TUTORIAL directory>
          USE customer
    

  2. Open the Debug window, and type "ALEN(arr)" (without the quotation marks). Observe the value displayed after issuing each of the following commands:

          COPY TO ARRAY arr FIELDS state FOR state = "CA"
          * arr has 123 elements, all of which are "CA".
    

          COPY TO ARRAY arr FIELDS state FOR state = "AK"
          * arr still has 123 elements, but issuing the command
          * DISPLAYMEMORY LIKE arr will show that only the first
          * element of arr is "AK"; the rest are "CA".
    

    NOTE: If the second COPY TO ARRAY command returns a smaller number of elements than those existing in the array, only that number of elements will be overwritten; the others will retain their former value.

    If the second COPY TO ARRAY command returns a larger number of elements than those existing in the array, the result set will be truncated to the number of elements in the array.

    To obtain correct results, you must use the RELEASE command to release the array between consecutive COPY TO ARRAY commands.

  3. Observe the value of ALEN(arr) after issuing the following commands:

          SELECT cno FROM customer INTO array arr WHERE state = "CA"
          * arr now has 123 elements, all of which are "CA".
    

          SELECT cno FROM customer INTO ARRAY arr WHERE cno = "AK"
          * ALEN(arr) =1; the value is "AK".
    

REFERENCES

"Commands & Functions," version 2.0, COPY TO ARRAY and SELECT - SQL "Language Reference," version 2.5, pages L3-317 and L3-862


Additional reference words: VFoxWin 3.00 FoxDos FoxWin 2.50 2.00 2.50a
dimension declare
KBCategory: kbprg
KBSubcategory: FxprgSql


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.