passing result of query to a varibale in ksh script

Hi,

I have a scenario where in i have to extarct max of one column and pass it to a variable.

i have tried to export the result as .dat file and read from that file.But my database is mainframe and it is not permitting me to export in .dat file.I have tried using .ixf file but reading from that file is little difficult.

So can anyone suggest some solution to assinn the result of query like
"select max(a) from b" to a variable.

Thanks !

What database is this ?

If you have an utility to access your db, and this utility returns a scalar result, then you can use that to script. For example, this is with oracle.

# su - oracle
/usr/users/oracle>
/usr/users/oracle> a=`sqlplus -s '/ as sysdba' << EOF
> set feedback off pages 0
> select max(1) from dual;
> EOF`
/usr/users/oracle> echo $a
1
/usr/users/oracle>

sqlplus is the utility I use to query the db. Try to find something equivalent in yours.

Hi fidodido,

My database is mainframe.So for the mainframes how can we modify the code?

db2 "connect to db user user1 using pwd"

db2 "SELECT MAX(ID) FROM ITEM" >>SV
echo SV

will this work?
OR is there any other solution to assign the value for mainframes