You can export queries (including queries on views) to a file from Interactive SQL with the Data menu, the OUTPUT statement, or the UNLOAD statement.
You can import and export files between SQL Anywhere and Adaptive Server Enterprise using the BCP FORMAT clause.
For more information, see Adaptive Server Enterprise compatibility.
To export query results (Interactive SQL Data menu)
Enter your query in the SQL Statements pane of Interactive SQL.
Choose SQL » Execute to display the result set.
Choose Data » Export.
Specify a location for the results and click Next.
For text, HTML, and XML files, type a file name in the File Name field and click Export.
For an ODBC database:
Click Close.
To export query results (Interactive SQL OUTPUT statement)
Enter your query in the SQL Statements pane of Interactive SQL.
At the end of the query, type OUTPUT TO 'filename'.
For example, to export the entire Employees table to the file employees.txt, enter the following query:
SELECT * FROM Employees; OUTPUT TO 'employees.txt'; |
Do any of the following:
To do this... | Use this clause... | Example... | ||
---|---|---|---|---|
Export query results and append the results to another file | APPEND |
|
||
Export query results and include messages | VERBOSE |
|
Choose SQL » Execute.
If the export is successful, the Messages tab displays the amount of time it to took to export the query result set, the file name and path of the exported data, and the number of rows written. If the export is unsuccessful, a message appears indicating that the export was unsuccessful.
For more information about exporting query results using the OUTPUT statement, see OUTPUT statement [Interactive SQL].
You can combine the APPEND and VERBOSE clauses to append both results and messages to an existing file.
For example, type OUTPUT TO 'filename' APPEND VERBOSE.
The OUTPUT statement with its clauses APPEND and VERBOSE are equivalent to the >#, >>#, >&, and >>& operators of earlier versions of Interactive SQL. You can still use these operators to redirect data, but the new Interactive SQL statements allow for more precise output and easier to read code.
For more information about APPEND and VERBOSE, see OUTPUT statement [Interactive SQL].
To export query results (UNLOAD statement)
In the SQL Statements pane, enter the UNLOAD statement. For example,
UNLOAD SELECT * FROM Employees TO 'employee_data.csv'; |
Choose SQL » Execute.
If the export is successful, the Messages tab displays the amount of time it to took to export the query result set, the file name and path of the exported data, and the number of rows written. If the export is unsuccessful, a message appears indicating that the export was unsuccessful.
Outputting NULLs using the OUTPUT statement
Send feedback about this page via email or DocCommentXchange | Copyright © 2008, iAnywhere Solutions, Inc. - SQL Anywhere 11.0.0 |