473,396 Members | 2,039 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Export Command - How to generate a row with column headers

I have been using the export command for quite some times to export
comma delimited file. I have always been looking at how to generate
the first row with the column header but never found a clean way to do
it. I have searched this newsgroup and the only suggestion found was
to cast all column to strings and do a union, or to add the first row
afterwards and I saw one suggestion where it was to create a unix
script.

Does anybody knows how to do this ? Or can you let me know if it is
not possible for comma delimited list to produce an output where the
first row contains the column header?

I found one way of doing it but it is sort of a HACK. You use WSF
format instead of DEL for the export and you can open that binary
output with Excel. (It's a WKS 1.2.3 file... Lotus note) For Example,
you run:
Db2export to "C:\you_file.xls" of WSF select * from your_table

Then, after you open the above file with Excel, you can save it as a
CSV format. The new file in the CSV format now contains the column
header as the first row.

Oct 12 '06 #1
5 30023

Here is a sample DOS BAT file (Although, this is not so elegant, it
will work):
DB2 "EXPORT TO Dept_Data.txt OF DEL SELECT * FROM DEPARTMENT"
DB2 "EXPORT TO Dept_Header.txt OF DEL Modified by NoCharDEL SELECT
SUBSTR(REPLACE(REPLACE(XMLSERIALIZE(CONTENT XMLAGG(XMLELEMENT(NAME c,
colname) ORDER BY colno) AS VARCHAR(100)),'<C>',', '),'</C>',''),3)
FROM syscat.columns WHERE tabschema='DB2ADMIN' AND
tabname='DEPARTMENT'"
copy Dept_Header.txt+Dept_Data.txt Dept_with_Header.txt

Oct 13 '06 #2
That works great thanks! ...but I had to remove the nochardel.

For some odd reason it doesn't work and give this error:

SQL3016N An unexpected keyword "nochardel" was found in the filetmod
parameter for the filetype.

I type "db2 ? export" and it shows these options that are available for
the DB version I have ( Database server = DB2/6000 8.2.2)

NODOUBLEDEL, LOBSINFILE, CHARDELx, COLDELx, DLDELx
DECPLUSBLANK, DECPTx, DATESISO, 1, 2, 3, 4, CODEPAGE=x
Is it possible with the options above to produce the same behavior as
nochardel? For example, somehow pass a space to CHARDELx?

Oct 13 '06 #3
I think RS/6000 is already get minor.
I also don't know DB2/6000.
But, if you know RS/6000 script, it would be easy to remove first
character and last character of a file.
So, my idea is as fllowing:
DB2 "EXPORT TO Dept_Data.txt OF DEL SELECT * FROM DEPARTMENT"
DB2 "EXPORT TO Dept_Header.txt OF DEL SELECT
SUBSTR(REPLACE(REPLACE(XMLSERIALIZE(CONTENT XMLAGG(XMLELEMENT(NAME c,
colname) ORDER BY colno) AS VARCHAR(100)),'<C>',', '),'</C>',''),3)
FROM syscat.columns WHERE tabschema='DB2ADMIN' AND
tabname='DEPARTMENT'"
/* insert OS/script to remove first and last character of Header.txt */
copy Dept_Header.txt+Dept_Data.txt Dept_with_Header.txt

Oct 16 '06 #4
Thanks Tonkuma!

Oct 19 '06 #5
Thanks Tonkuma!

Oct 19 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: ccjunk | last post by:
This may be a simple one but I have been working on it without joy for a couple of days now. Reading books and searching these groups hasn't helped yet either. I am trying to create a table...
2
by: Yaron | last post by:
Hi I'm creating a control very similar to the ListView in Details mode. I'm confused as to how to go about drawing the column headers at the top As the column headers are static and stay in one...
2
by: David Veeneman | last post by:
How can I set a bound DataGridView control to use a dataset table's column captions, instead of column names? I'm working with a DataGridView control, which I have bound to a table in a dataset....
4
by: Hans Merkl | last post by:
Hi, Is there a way to show the column headers of a GridView control even if there is no data? The only thing I see is the EmptyDataTemplate but I would also like to display the column headers. ...
1
by: ElenaR | last post by:
I need to figure out how to name my column headers in a DataGrid. In VB6, I could write DataGrid1.Columns(0).Caption = "ID". What is the format for VB.NET? Thanks in Advance!
2
by: John Walker | last post by:
Hi, We have a datagrid with column headers. If the datagrid has more than say 25 rows the user needs to scroll down to be able to see the rest of the grid. When the user does this the column...
6
by: no_spam_for_gman | last post by:
Hi, I have been using the db2 export function for quite sometimes. Everytime I want to use it I have to remove every carriage return from my SQL statement and have it all on one line as shown in...
0
by: CDonlan | last post by:
Here is how im exporting //Clear response content and headers response.Clear(); response.ClearContent(); response.ClearHeaders(); //Add header response.AddHeader("content-disposition",...
1
Denburt
by: Denburt | last post by:
This function was originally created back in the dawn of time, over the years I have made a number of changes and after searching the net I still didn't see 1 that allowed for the use of column...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.