1

I want to export the column names into excel sheet by running the query in Teradata. I used ctrl+c but it didnt work. Thanks in advance.

ecenurozturk
  • 31
  • 2
  • 8

4 Answers4

1

Change your settings in Result Set View Preferences\Copy Options\ check "Copy Include Column Headers"

The "Result Set View Preferences" is the first button that looks like pliers on the result set view window.

0

To get column names, open you answerset, and save the result set. File > save as >

0

I've found the answer show table tablename

ecenurozturk
  • 31
  • 2
  • 8
  • 1
    If you simply want a list of column names better user `HELP TABLE tablename` or query `dbc.columnsV` maybe ordered by `ColumnId` – dnoeth Feb 17 '18 at 10:10
0

I frequently want to report out the colums and the dbc.columns is the best way to do this. They all come out right padded so a trim makes them paste into excel nicely. I also added a case statement that will translate the datatype for you.

sel
  trim(databasename)
, trim(tablename)
, trim(columnname)
, max(case
   when columntype = 'D'  then 'decimal(' || decimaltotaldigits || ', ' || decimalfractionaldigits || ')'
   when columntype = 'CV' then 'varchar(' || columnlength || ')'
   when columntype = 'CF' then 'char('    || columnlength || ')'
   when columntype like 'I%'  then 'integer'
   else 'unknown' end) as colDDL
from dbc.columns where tablename in (<sometableList>)
and databasename in (<someDBList>)
order by column_id

A Full List of DBC.columns data tpe mapping example:

create volatile table vt_woe_col_list
as (
select
  trim(columnname) as column_name
, case when ColumnType in ('CF','CV')             then 'Character'
       when ColumnType in ('D','F','I1','I2','I') then 'Numeric'
       when ColumnType in ('DA')                  then 'Date'
       when ColumnType in ('SZ','TS')             then 'TimeStamp'
       else 'Skip' end as process_type
, case trim(columntype)
    when 'AT' then 'TIME' 
    when 'BF' then 'BYTE'
    when 'BO' then 'BLOB'
    when 'BV' then 'VARBYTE'
    when 'CF' then 'CHAR'
    when 'CO' then 'CLOB'
    when 'CV' then 'VARCHAR'
    when 'D'  then 'DECIMAL'
    when 'DA' then 'DATE'
    when 'DH' then 'INTERVAL DAY TO HOUR'
    when 'DM' then 'INTERVAL DAY TO MINUTE'
    when 'DS' then 'INTERVAL DAY TO SECOND'
    when 'DY' then 'INTERVAL DAY'
    when 'F'  then 'FLOAT'
    when 'GF' then 'GRAPHIC'
    when 'GV' then 'VARGRAPHIC'
    when 'HM' then 'INTERVAL HOUR TO MINUTE'
    when 'HR' then 'INTERVAL HOUR'
    when 'HS' then 'INTERVAL HOUR TO SECOND'
    when 'I1' then 'BYTEINT'
    when 'I2' then 'SMALLINT'
    when 'I'  then 'INTEGER'
    when 'MI' then 'INTERVAL MINUTE'
    when 'MO' then 'INTERVAL MONTH'
    when 'MS' then 'INTERVAL MINUTE TO SECOND'
    when 'SC' then 'INTERVAL SECOND'
    when 'SZ' then 'TIMESTAMP WITH TIME ZONE'
    when 'TS' then 'TIMESTAMP'
    when 'TZ' then 'TIME WITH TIME ZONE'
    when 'YM' then 'INTERVAL YEARTO MONTH'
    when 'YR' then 'INTERVAL YEAR'
    when 'UT' then 'UDT Type'
    end as column_type_desc
,  a.*
from dbc.columns A
where trim(tablename   )='t_woe_data_samp'
  and trim(databasename)= 'DUCSMAD'
) with data
primary index(column_name)
on commit preserve rows;
Daniel Patriarca
  • 361
  • 3
  • 20
  • `dbc.columns` (like all non-V-views) is a deprecated view since TD12, you better switch to `dbc.ColumnsV. It returns VarChar(128) vs. Char(30), which also removes the need for all those TRIMs. – dnoeth Mar 20 '19 at 20:28