How to capture result of bteq script into a variable

Tools & Utilities
Enthusiast

How to capture result of bteq script into a variable

Hi

I tried to capture the result of bteq script into a variable and it did not work

Could any one of you guys help me with this

i tried this way
but did not work

var=`bteq << EOF
.logon server/username,password
select count(*) from databasename.tablename;
.exit
EOF
`

it connected to teradata
executed query
but result of count(*) is not capture by 'var'

Any suggestions please
i guesss this work well in oracle
but it did not work here

thanks

2 REPLIES
Fan

Re: How to capture result of bteq script into a variable

Hi,

Rather than storing the result in a variable, you can prepare a report i.e file which will contain the result of SQL query which is executed in bteq.

.export report file= .out
.set rtitle '<REPORT TITLE NAME'
.set format on
.set separator "|"

<
SQL QUERY;
>

.set format off
.export reset
.exit;
Enthusiast

Re: How to capture result of bteq script into a variable

Hi:
Thankyou for ur great help
as per ur suggestion my query result is capturing in a file
But if that is in a variable, I can use that variable in a loop
which is my next step in a cobined script of unix and bteq
so with any further improvement in ur suggestion can u let me know
how i can use the result value of query in bteq without variable

and also, in bteq, can i use same output file to over write my result
while i am sending result from a loop to same file??
If so, could you let me know