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

SQL Anywhere 12.0.1 » SQL Anywhere Server - SQL Usage » Remote data and bulk operations » Data import and export » Data import » Import data with the INPUT statement


Importing data with the INPUT statement

You can import data into a database from a text file or from a CSV file using Interactive SQL.



Context and remarks

Because the INPUT statement is an Interactive SQL statement, you cannot use it in any compound statement (such as an IF statement) or in a stored procedure.

 Import data (INPUT statement)
  1. Create and save a text file named new_employees.txt with the following values (on a single line):

    101,500,'Chan','Julia',100,'300 Royal Drive',
  2. Open Interactive SQL and connect to the SQL Anywhere 12 sample database.

  3. Enter an INPUT statement in the SQL Statements pane.

    INPUT INTO Employees
    FROM c:\new_employees.txt
    SELECT * FROM Employees;

    In this statement, the name of the destination table in the SQL Anywhere 12 sample database is Employees, and new_employees.txt is the name of the source file.

  4. Execute the statement.

    If the import is successful, the Messages tab displays the amount of time it to took to import the data. If the import is unsuccessful, a message appears indicating why the import was unsuccessful.

 Input data from an Excel CSV file using the INPUT statement
  1. In Excel, save the data from your Excel file into a comma delimited (CSV) file. For example name the file c:\test\finance_comma_delimited.csv

  2. In Interactive SQL, connect to a SQL Anywhere database such as the demo12 database.

  3. Create a table named imported_sales and add the required columns. You cannot use the CREATE TABLE clause to create a table when inputting from a csv file.

  4. Execute an INPUT statement using the SKIP clause to skip over the column names that Excel places in the first line in the CSV file.

    INPUT INTO "imported_sales" FROM 'c:\\test\\finances.csv' SKIP 1


The data is imported into the specified database.