How to send SQL query result on EMAIL using Bteq script

Analytics

How to send SQL query result on EMAIL using Bteq script

I want to create a bteq script for sending a mail of sql query result to certain email. Pls suggest..

1 REPLY

Re: How to send SQL query result on EMAIL using Bteq script

This can be done via multiple ways, one of the way you can do is

 

1. Configure postfix on you linux host (You can find steps on internet, please google it).

2. Create a BTEQ script.

eg:- bteqtest.btq

.LOGON localhost/dbc,dbc;
SELECT *FROM DBC.DBCINFO;
.LOGOFF;

3. Create a Shell script or execute the script from shell or call from CRON.

eg:- executebteq.sh

/opt/teradata/client/15.10/bin/bteq < /root/bteqtest.btq
#Uncomment below line if calling script as part of CRON
#mail -a /root/bteqresultset/sql.out -s "SQL Result" user@example.com < /dev/null

4. [Optional] Call the script via crontab

*/1 * * * * /root/executebteq.sh > /root/bteqresultset/sql.out 2>&1

5. Run below command to send email with results. [Ignore if using as part of CRON]

mail -a /root/bteqresultset/sql.out -s "SQL Result" user@example.com < /dev/null

 

 

Hope this helps.