SELECT - SQL Command - INTO or TO Clause
The INTO or TO clauses specify output options that determine the location for storing or sending the final query results from a SQL SELECT statement.
For more information, see SELECT - SQL Command.
The detailed syntax for the INTO or TO clause is as follows:
- [INTO StorageDestination]
Stores the query results in an array, cursor, or table.
If you do not include the INTO clause, query results are displayed in a Browse window by default. To direct the query results to the printer or a file, use the TO clause.
The following table describes locations in which you can store the query results using the INTO clause.
Stores query results in a memory variable array.
If the query selects zero records, the array is not created.
CURSOR CursorName [NOFILTER | READWRITE]
Stores query results in a temporary cursor.
If you specify the name of an open table, Visual FoxPro generates an error message. After SELECT is executed, the temporary cursor remains open and is active and read-only unless you specify the READWRITE option. When you close this temporary cursor, it is deleted. Cursors can exist as a temporary file on the drive or volume specified by SORTWORK.
NOFILTER creates a cursor that can be used in subsequent queries.
Including NOFILTER can reduce query performance because it creates a temporary table on disk. When the cursor is closed, the temporary table is deleted from disk.
READWRITE specifies that the temporary cursor is modifiable. If the source table or tables use auto-incrementing, the cursor created with READWRITE does not inherit those settings. You can create more than one structural index on a cursor using the READWRITE argument.
TABLE TableName [DATABASE DatabaseName [NAME LongTableName]]
Stores query results in a table.
If you specify a table that is open, and SET SAFETY is set to OFF, Visual FoxPro overwrites the table without warning.
If you do not specify an extension, Visual FoxPro gives the table a .dbf extension. The table remains open and active after SELECT is executed.
DATABASE DatabaseName specifies a database you can add the table to.
NAME LongTableName specifies a long name for the table. Long names can contain up to 128 characters and can be used in place of short file names in the database.
- [TO DisplayDestination]
Sends the query results to a file, printer, main Visual FoxPro window, or an active user-defined window.
Visual FoxPro disregards the TO clause if you also include the INTO clause in the same query.
The following table describes locations that you can send the query results using the TO clause.
FILE FileName [ADDITIVE]
Specifies an ASCII text file that you can direct the query results to.
ADDITIVE appends query output to the existing contents of the text file specified by FileName.
Directs query output to a printer.
PROMPT displays a printer dialog box before printing begins. You can adjust printer settings in the dialog box. The printer settings that you can adjust depend on the currently installed printer driver.
Directs query output to the main Visual FoxPro window or an active user-defined window.
The following code shows a summary of the main clauses of the SELECT - SQL Command:
SELECT Select_List FROM Table_List ...[WITH (BUFFERING = lExpr)] [WHERE Conditions] [GROUP BY Column_List] [UNION Clause] [HAVING Conditions] [ORDER BY Column_List] [INTO Clause | TO Clause ] [Additional_Display_Options]
For more information about a particular clause of the SQL SELECT command, see the following topics:
The following example stores the contents of a query into a table using INTO TABLE TableName clause. The example stores the contents of the Company, Order_Date, and Shipped_On fields from the Customer and Order tables, which are joined on the Cust_ID field, in a third table called CustShip. The example then opens a Browse window for the new table. The SELECT statement specifies local aliases for the tables to distinguish the same field name, Cust_ID, in both tables.
CLOSE ALL CLOSE DATABASES OPEN DATABASE (HOME(2) + 'Data\TestData') SELECT TAlias1.company, TAlias2.order_date, TAlias2.shipped_on ; FROM customer TAlias1, orders TAlias2 ; WHERE TAlias1.cust_id = TAlias2.cust_id ; INTO TABLE custship.dbf BROWSE