Exporting result of select statement to CSV format in DB2
This is how you can do it from DB2 client.
Open the Command Editor and Run the select Query in the Commands Tab.
Open the corresponding Query Results Tab
Then from Menu --> Selected --> Export
Is there any way by which we can export the result of a select statment to CSV file, just like in MySQL.
SELECT col1,col2,coln into OUTFILE 'result.csv' FIELDS TERMINATED BY ',' FROM testtable t;
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)
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;
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.