Assigning value of a select count(*) from tablename ( run on db2 ) to a unix variable

Hi All,

I have browsed through the forums for a similar topic, but there is no topic which explains about this problem, when the backend is DB2.

I want to assign the output of a select count(*) from tablename to a unix variable in a shell script.

I am using ksh.

The database used to run the query is DB2 , please advise

Regards
Siddarth

please try var='select count(*) from tablename' and then the database connection points

Hi,

I have already tried that and it didnt work before.

I am establishing a connection to the database at the very start of the script and running this query after a couple of commands.

This syntax doesnt assigns value to the variable

Follow this format:

db2 connect to dbname...
myvar=$(db2 -x "select count(*) from schema.table")
print "myvar = $myvar"
db2 connect reset