Contents Index Export tools Exporting databases

ASA SQL User's Guide
  Importing and Exporting Data
    Exporting

Exporting query results


You can export queries (including queries on views) to a file from Interactive SQL using the Data menu or the OUTPUT statement.

You can import and export files between Adaptive Server 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)

  1. Enter your query in the SQL Statements pane of the Interactive SQL window.

  2. Click Execute SQL statement(s) to display the result set.

  3. Choose Data > Export.

    The Save As dialog appears.

  4. Specify a name and location for the exported data.

  5. Specify the file format and click Save.

    If the export is successful, the Messages pane displays the amount of time it to took to export the query result set, the filename and path of the exported data, and the number of rows written.

    If the export is unsuccessful, a message appears indicating the export was unsuccessful.

To export query results (Interactive SQL OUTPUT statement)

  1. Enter your query in the SQL Statements pane of the Interactive SQL window.

  2. At the end of the query, type OUTPUT TO 'c:\filename'.

    For example, to export the entire employee table to the file employee.dbf, enter the following query:

    SELECT *
    FROM employee;
    OUTPUT TO 'c:\employee.dbf'
  3. If you want to export query results and append the results to another file, add the APPEND statement to the end of the OUTPUT statement.

  4. If you want to export query results and include messages, add the VERBOSE statement to the end of the OUTPUT statement.

    For example,

    SELECT *
    FROM employee;
    OUTPUT TO 'c:\employee.dbf' VERBOSE
  5. If you want to specify a format other than ASCII, add a FORMAT clause to the end of the query.

    For example,

    SELECT *
    FROM employee;
    OUTPUT TO 'c:\employee.dbf'
    FORMAT dbaseiii;

    where c:\employee.dbf is the path, name, and extension of the new file and dbaseiii is the file format for this file. You can enclose the string in single or double quotation marks, but they are only required if the path contains embedded spaces.

    Where dbaseiii is the file format for this file. If you leave the FORMAT option out, the file type defaults to ASCII.

  6. Execute the statement.

    If the export is successful, the Messages pane displays the amount of time it to took to export the query result set, the filename and path of the exported data, and the number of rows written. If the export is unsuccessful, a message appears indicating the export was unsuccessful.

    For more information about exporting query results using the OUTPUT statement, see OUTPUT statement [Interactive SQL].

Tips 
You can combine the APPEND and VERBOSE statements to append both results and messages to an existing file. For example, type OUTPUT TO 'filename.sql' APPEND VERBOSE. For more information about APPEND and VERBOSE, see the OUTPUT statement [Interactive SQL].

The OUTPUT TO, APPEND, and VERBOSE statements 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.

To export query results (UNLOAD statement)


Contents Index Export tools Exporting databases