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.

Prerequisites

None.

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',
    'Springfield','OR','USA','97015','6175553985',
    'A','017239033',55700,'1984-09-29',,'1968-05-05',
    1,1,0,'F'
  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
    FORMAT TEXT;
    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

Results

The data is imported into the specified database.

Next

None.