Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2011
    Posts
    1

    Question Unanswered: 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

  2. #2
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    3,483
    How about this?
    EXPORT TO filename OF DEL ... VALUES ('col1' , 'col2') UNION ALL SELECT col1 , col2 FROM table

  3. #3
    Join Date
    Aug 2008
    Location
    Toronto, Canada
    Posts
    2,367
    What if col1 and col2 are defined as int?

  4. #4
    Join Date
    Aug 2008
    Location
    Toronto, Canada
    Posts
    2,367
    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.

  5. #5
    Join Date
    Jan 2007
    Location
    Jena, Germany
    Posts
    2,721
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •