Skip to content

Instantly share code, notes, and snippets.

@neilkod
Created August 19, 2011 15:08
Show Gist options
  • Save neilkod/1157004 to your computer and use it in GitHub Desktop.
Save neilkod/1157004 to your computer and use it in GitHub Desktop.
bteq question
goal is to set an environment variable to the result of a teradata query
-bash-3.1$ cat test_bteq.cmd
.logon xxx.yyy.zzz.bbb/username,password
select count(*) from sql_class.orders;
.QUIT
I would like to know if its possible to do something like this
export ORDERS_COUNT=`cat test_bteq.cmd|bteq`
and $ORDERS_COUNT would be the result of select count(*) From sql_class.orders;
@robpaller
Copy link

In a shell script:

bteq <<EOBTQ

.LOGON xxx.yyy.zzz.bbb/username,password

.SET TITLEDASHES OFF

.OS rm test.exp

.EXPORT REPORT FILE=test.exp

SELECT COUNT(*) (TITLE '')
FROM DBC.DBCInfo;

.EXPORT RESET

.SET TITLEDASHES ON

.QUIT ERRORLEVEL;

EOBTQ

export ORDERS_COUNT=$(cat test.exp)
echo $ORDERS_COUNT

EOF

It's kind of a cheat having to dump the COUNT(*) to a flat file, but I think it is the only way to get BTEQ to interact with the external environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment