Export with header using TPT

Tools & Utilities
Enthusiast

Export with header using TPT

Hi,

I am using TPT export for doing data export from TD to a file and want to include column headers to the generated file.

I would like to know if there are any attributes that is included with newer version of tpt that we can use for this., I am using TPT version 14.10

Regards,

Srivignesh KN

4 REPLIES
Teradata Employee

Re: Export with header using TPT

The Export (and SQL Selector) operator(s) is/are not capable of extracting out the column headers from the database.

-- SteveF

Re: Export with header using TPT

As Steve says there are not an attribute to get file with columns header.

Many times i used one of two options:

1 - Use OS COMMAND to concatenate two files, headers file and export file. On windows "type header.txt export.txt > file.txt". On Unix "cat header.txt export.txt > file.txt"...

2 - Generate one row with columns header and Id and, make union with the data using row_number to generate id and. Finally order by id.

LOCKING ROW FOR ACCESS
SELECT A.Col1
,A.Col2
,A.Col3
,A.Col4
,A.Col5
,A.Col6
,A.Col7
FROM (-- A

SELECT 'Col1' (VARCHAR(100)) AS Col1
,'Col2' (VARCHAR(100)) AS Col2
,'Col3' (VARCHAR(100)) AS Col3
,'Col4' (VARCHAR(100)) AS Col4
,'Col5' (VARCHAR(100)) AS Col5
,'Col6' (VARCHAR(100)) AS Col6
,0 (INTEGER) AS Id
FROM SYS_CALENDAR.CALENDAR
WHERE Calendar_Date = CURRENT_DATE

UNION

SELECT CAST(Col1 AS DATE FORMAT 'YYYYMMDD') (VARCHAR(100)) AS Col1
,CAST(Col2 AS INTEGER) (VARCHAR(100)) AS Col2
,CAST(Col3 AS ...) (VARCHAR(100)) AS Col3
,CAST(Col4 AS ...) (VARCHAR(100)) AS Col4
,CAST(Col5 AS ...) (VARCHAR(100)) AS Col5
,CAST(Col6 AS ...) (VARCHAR(100)) AS Col6
,CAST(Col7 AS DECIMAL(15,2)) (VARCHAR(100)) AS col7
,ROW_NUMBER() OVER(ORDER BY Col1) (INTEGER) AS Id
FROM DB.Table_
WHERE Col1 = ...

) A
ORDER BY Id
;

Regards.

Enthusiast

Re: Export with header using TPT

Thank you MissGate & Steve, 

Teradata Employee

Re: Export with header using TPT

If the UNION form is used, it is a good idea to use UNION ALL so that the engine is not forced to do a duplicate elimination pass over the combination of the header row and the data.