Setting variable for query using iSql / Korn Shell

Hi All-

First time using iSql.
I have 4 query files - some have more than 1 line of sql statements

After a bit of research it appears I can just use the -i command and specify the input file.

Questions:

  1. Does it matter that there are multiple queries in each file? Do I need to have special formatting within the files to ensure everything processes correctly?
  2. Is there any way to pass in variables for the query statements?

Thanks!

1.) Multiple queries can be separated by semi-colons.

2.) Within the SHELL, you can use this:


isql << EOF

SELECT some_stuff
  FROM table_some_thing
 WHERE some_field = "$some_input_variable" ;

EOF

Ok - so I can put multiple queries in my file as long as they all have the semi colon.

since I have a file full of queries, I would want to use the "-i" option. Unless I am missing something, it seems like putting them hardcoded into the script would be way too much. Is there any way for me to pass a variable into the iSql command when it runs the file?

Using my answer to #2.

Substitute a positional parameter like so:

% my_sql_stuff.sh first_arg second_arg

inside the my_sql_stuff.sh:


isql << EOF

SELECT some_stuff
  FROM table_some_thing
 WHERE some_field = "$1"
   AND something_else = "$2";

EOF