Exporting result of select statement to CSV format in DB2



Answers

This is how you can do it from DB2 client.

  1. Open the Command Editor and Run the select Query in the Commands Tab.

  2. Open the corresponding Query Results Tab

  3. Then from Menu --> Selected --> Export

Question

Is there any way by which we can export the result of a select statment to CSV file, just like in MySQL.

MySQL Command;

SELECT col1,col2,coln into OUTFILE  'result.csv' FIELDS TERMINATED BY ',' FROM testtable t;



Quicker ways to migrate data from DB2 to SQL Server?

You probably want to export the data to a csv file such as this answer on :

EXPORT TO result.csv OF DEL MODIFIED BY NOCHARDEL SELECT col1, col2, coln FROM testtable;

(Exporting result of select statement to CSV format in DB2)

Once its a CSV file you can import it into SQL Server using either BCP or SSIS both of which are extremely fast especially if you use file lock on the target table.




How to export SQL results to CSV from an SQL script using DB2 database?

if you are on iseries (older name AS400), you can use CPYTOIMPF and specify the TOSTMF option to place a CSV file on the IFS directory

do and sql create table :

create table yourlib/yourfile as (  ---- your query ----) with data

like this :

CPYTOIMPF FROMFILE(yourlib/yourfile ) TOSTMF('/outputfile.csv') STMFCODPAG(*PCASCII) RCDDLM(*CRLF)

you can use this command into script sql like this

CL: CPYTOIMPF FROMFILE(yourlib/yourfile ) TOSTMF('/outputfile.csv') STMFCODPAG(*PCASCII) RCDDLM(*CRLF)



Links



Tags