Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SAP Sybase SQL Anywhere 16.0 » SQL Anywhere Server - SQL Usage » Data import and export » Data export » Tips on exporting data with the OUTPUT statement

 

Exporting data to a CSV file

In Interactive SQL, you can export data from your database to a CSV file by using the OUTPUT statement.

Prérequis

You must have the SELECT ANY TABLE system privilege or SELECT privilege on the table.

 Task
  1. In Interactive SQL, connect to a SQL Anywhere database.

  2. Execute an OUTPUT statement with the clauses FORMAT TEXT, QUOTE '"', and WITH COLUMN NAMES to create a comma-delimited format with the column names in the first line of the file. String values are enclosed with quotation marks. For example:

    SELECT * FROM SalesOrders; 
    OUTPUT TO 'C:\\LocalTemp\\newSales.csv' 
        FORMAT TEXT
        QUOTE '"'
        WITH COLUMN NAMES;

Résultat

The data is exported to the specified CSV file.

Exemple

The following example exports the data from the Employees table in the SQL Anywhere sample database to Employees.csv in the C:\LocalTemp directory.

SELECT * FROM Employees;
OUTPUT TO C:\LocalTemp\Employees.csv
    FORMAT TEXT;

 See also