If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > How to fetch Column names using a select query?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-23-11, 12:44
ashmahto ashmahto is offline
Registered User
 
Join Date: Apr 2011
Posts: 1
Question How to fetch Column names using a select query?

Hi,
Is there an option in export command to fetch the column names used in the query as well as the data returned by the query.

Also,Ne other way to achieve this is also welcome.

Input Query
select col1,col2 from table

Output I want is
col1,col2
a,b
c,d
e,f



Any Help appreciated


Thanks
Ashutosh
Reply With Quote
  #2 (permalink)  
Old 04-23-11, 13:42
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,195
How about this?
EXPORT TO filename OF DEL ... VALUES ('col1' , 'col2') UNION ALL SELECT col1 , col2 FROM table
Reply With Quote
  #3 (permalink)  
Old 04-23-11, 23:17
db2girl db2girl is offline
∞∞∞∞∞∞
 
Join Date: Aug 2008
Location: Toronto, Canada
Posts: 1,816
What if col1 and col2 are defined as int?
Reply With Quote
  #4 (permalink)  
Old 04-23-11, 23:37
db2girl db2girl is offline
∞∞∞∞∞∞
 
Join Date: Aug 2008
Location: Toronto, Canada
Posts: 1,816
I think the column names in "EXPORT TO filename OF DEL ... VALUES ('col1' , 'col2')" would have to be changed to numbers if the columns are defined as int.
Reply With Quote
  #5 (permalink)  
Old 04-25-11, 16:19
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Or you cast the results of the SELECT to CHAR:
Code:
EXPORT ... VALUES ('col1', 'col2) UNION ALL SELECT CHAR(col1), CHAR(col2) FROM table
Of course, this will most probably result in rounding differences on floating point values.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On