tags:

views:

234

answers:

1

I would like to be able to produce a file by running a command or batch which basically exports a table or view (SELECT * FROM tbl), in text form (default conversions to text for dates, numbers, etc are fine), tab-delimited, with NULLs being converted to empty field (i.e. a NULL colum would have no space between tab characters, with appropriate line termination (CRLF or Windows), preferably also with column headings.

This is the same export I can get in SQL Assistant 12.0, but choosing the export option, using tab delimiter, setting my NULL value to '' and including column headings.

I have been unable to find the right combination of options - the closest I have gotten is by building a single column with CAST and '09'XC, but the rows still have a leading 2-byte length indicator in most settings I have tried. I would prefer not to have to build large strings for the various different tables.

+1  A: 

To eliminate the 2-byte in the FastExport output:

.EXPORT OUTFILE &dwoutfile MODE RECORD FORMAT TEXT;

And your SELECT must generate a fixed length export field e.g. CHAR(n). So you will inflate the size of the file and end up with a delimited but fixed length export file.

The other option is if you are in a UNIX/Linux environment you can post process the file and strip the leading two bytes or write an ASXMOD in C to do it as the records are streamed to the file.

RobPaller
Thanks - I see that the fixed length appears to be the key in supressing the leading count column.
Cade Roux
How about the header row? Any way to do that in FASTEXPORT?
Cade Roux
UNION it to the second statement and cast both to the max length which ever is longer.
RobPaller
Also, I discovered I could just put another SELECT before it without using UNION:SELECT CAST('COLNAME' || '09'XC || 'COLNAME' || '09'XC || 'GRP_DESC' AS CHAR(N)) AS HEADINGS FROM (SELECT 1 AS NUM) AS TBL (NUM) ;
Cade Roux
I was just going to mention concatenating the hex string '09'XC to produce a TAB delimited file.
RobPaller