# Running scripts in teradata

Let us assume, we have a data warehouse in teradata. Let us suppose that this data warehouse is loaded with a set of scripts. In principle it could be done. The question then arises how the scripts are run. An example could clarify this. The example looks like:

.logon oTDD001.s2.ms.****.com/TOM.VAN-MAANEN, pau26688
.export report file=C:\Users\TOM.VAN-MAANEN\phi.txt
.set retlimit 20
SELECT	'"'||trim(Ident)||'";"'|| trim(Serial)||'";"'|| trim(Node)||'"' FROM	SAN_D_FAAPOC_01.TestUnicode;
.export reset;
.quit


The first line of this script creates a connection to a Teradata machine. The second line allocates a file that will be used to write data to. The fourth line is standard example where records from a table are exported. The last lines finishes the export and finishes the export from a table.
This scripts is called by a piped command where the script is sent to the bteq:

C:\Users\TOM.VAN-MAANEN>bteq < bteq.txt
BTEQ 13.10.00.01 Thu May 22 11:28:08 2014

+---------+---------+---------+---------+---------+---------+---------+----
.logon oTDD001.s2.ms.unilever.com/TOM.VAN-MAANEN,

*** Logon successfully completed.
*** Teradata Database Release is 14.00.06.05
*** Teradata Database Version is 14.00.06.05
*** Transaction Semantics are BTET.
*** Session Character Set Name is 'ASCII'.

*** Total elapsed time was 1 second.

+---------+---------+---------+---------+---------+---------+---------+----
.export report file=C:\Users\TOM.VAN-MAANEN\phi.txt
*** To reset export, type .EXPORT RESET
+---------+---------+---------+---------+---------+---------+---------+----
.set retlimit 20
+---------+---------+---------+---------+---------+---------+---------+----
insert into SAN_D_FAAPOC_01.TestUnicode(ident,node,serial)
values('Test├╣─ÖSummary','Test├╣─ÖSummary',' 19');

*** Insert completed. One row added.
*** Total elapsed time was 1 second.

+---------+---------+---------+---------+---------+---------+---------+----
SELECT '"'||trim(Ident)||'";"'|| trim(Serial)||'";"'|| trim(Node)||'"'
FROM SAN_D_FAAPOC_01.TestUnicode;

*** Query completed. 16 rows found. One column returned.
*** Total elapsed time was 1 second.

+---------+---------+---------+---------+---------+---------+---------+----
.export reset;
*** Output returned to console.
+---------+---------+---------+---------+---------+---------+---------+----
.quit
*** You are now logged off from the DBC.
*** Exiting BTEQ...
*** RC (return code) = 0

C:\Users\TOM.VAN-MAANEN>