0

I want to store my Query results in an csv outfile using SQL script. Can someone help me with an SQL script which can store the results in an CSV file. I'm using db2 database.

Thanks in advance!

Tech Guy
  • 417
  • 2
  • 7
  • 23
  • 2
    Possible duplicate of [Exporting result of select statement to CSV format in DB2](http://stackoverflow.com/questions/1058433/exporting-result-of-select-statement-to-csv-format-in-db2) – Stavr00 Nov 17 '16 at 18:35

2 Answers2

0

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)
Esperento57
  • 16,521
  • 3
  • 39
  • 45
0

I suggest you just use a database client. If it's possible in your case of course. For example SQuirreL SQL Client has an ability to export SQL result as CSV, Excel spreadsheet or XML. It's free and open source

siarheib
  • 159
  • 1
  • 8