cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

unload table with column names

Former Member
9,468

I am new to Sybase, hopefully someone can help me with this problem.

SELECT * FROM temp_data order by r_date, r_time;
OUTPUT TO 'C:\\files\\headerfile.txt' 
    FORMAT TEXT
    DELIMITED BY '\\x09'
    QUOTE ''
    ENCODING 'UTF-8'
    WITH COLUMN NAMES;

This code works for me but unfortunately WITH COLUMN NAMES; can not be used in a stored procedure. Then I tried:

unload select location, r_date, r_time, ct_codel_code_title from temp_data 
    TO 'C:\\files\\headerfile.txt'
    FORMAT TEXT
    DELIMITED BY '\\x09'
    QUOTE ''
    ENCODING 'UTF-8'

still the column name don't appear. Can anyone help?

View Entire Topic
justin_willey
Participant

If you were wanting to "future proof" against additional columns being added in future, you could select the column names from the SYS.SYSCOLUMNS view - something like:

select list(string('"',cname,'"'),char(09) order by colno asc)
  from sys.syscolumns where creator = 'dba' and tname = 'temp_data' ;

Ordering by colno should ensure that your columns are listed in the same order as the result set produced by select *