Pass a variable to SQL script

Hi Guys,

I like to pass a variable to a sql file in a unix script..

I tried a below code..

 
var=200903
 
db2 -vf  test.sql 200903

test.sql is as below.

select *  from db2.users where quarter = $1;

Please tell me where i go wrong..

Thanks in advance,
Magesh

The user running the script has the correct permissions to execute both the script and the SQL code?
For correcting your issue, you will probably benefit from having a user defined function in DB2 which extracts the value in question.

hi friend,

try this,

var=200903

sqlplus -s test.sql $var

and select * from db2.users where quarter = &1 ;