RE: Embedded SQL
Posted in 1995
On Wed, 18 Oct 1995 20:29:41 GMT dray@icsware.com wrote:
> Is there a way to use variables in embedded sql commands in C/UNIX
>environment? This is what I want to do
> select :var_column_name from :var_table_name;
> I know how to host variables but wanted to know if host variables
>canbe used for the table and column names.
>Thanks in advance
>
>
Another method to all those I've seen this morning and in my experience is by far the
simplest is to embed your SQL in a Unix shell 'here' document. Here documents
( or whatever they're called ) allow you to simulate the standard input of a command such
as dbaccess or isql. An example is probably the best way to demonstrate this.
#! /bin/ksh
col="tabname"
table="systables"
dbaccess - - <<SQL
database jsinc_test;
select $col from $table
order by 1
;
SQL
This works fine on my HP and I've been using this method for years on lots of different
unix systems. And if you have not got ESQL/C or 4GL then shell scripts are the only way.
Dont forget to change the database name in the above example.
HTH.
-------------------------------------
Name: Richard Yeardly
E-mail: Richard Yeardly <ryeardly@eurobrok.co.uk>
Date: 10/20/95