In Interactive SQL you can export data from your database to an Excel or CSV file using the OUTPUT statement.
Prerequisites
None.
Context and remarks
Many.
In Interactive SQL, connect to a SQL Anywhere database.
Execute an OUTPUT statement using the READONLY clause. For example:
SELECT * FROM SalesOrders; OUTPUT USING 'Driver=Microsoft Excel Driver (*.xls); DBQ=c:\\test\\sales.xls; READONLY=0' INTO "newSalesData"; |
A new Excel file, named sales.xls, is created. It will contain a worksheet called newSalesData.
Note that the Microsoft Excel driver is a 32-bit driver so the 32-bit version of Interactive SQL is required for this example.
In Interactive SQL, connect to the SQL Anywhere database.
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 will be enclosed with quotation marks.
SELECT * FROM SalesOrders; OUTPUT TO 'c:\\test\\sales.csv' FORMAT TEXT QUOTE '"' WITH COLUMN NAMES; |
Example
The following example exports the data from the Employees table in the SQL Anywhere sample database to a .txt file named Employees.txt.
SELECT * FROM Employees; OUTPUT TO Employees.txt FORMAT TEXT; |
The following example exports data from the Employees table in the SQL Anywhere sample database to a new table in a SQL Anywhere database named mydatabase.db
SELECT * FROM Employees; OUTPUT USING 'driver=SQL Anywhere 12;UID=dba;PWD=sql;DBF=C:\Tobedeleted\mydatabase.db;CON=''''' INTO "dba"."newcustomers" CREATE TABLE ON; |
Discuss this page in DocCommentXchange.
|
Copyright © 2012, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.1 |