Re: passing variables to sql statements in a Unix shell script
Posted in 1998
In article <eVEbENM89GA.207@upnetnews02.moswest.msn.net>,
kirt_t@email.msn.com (Kirt) wrote:
> I am trying to pass a variable array in the from statement to select
> from a
> list of table in a loop. I have been unable to make it work. Is there
> a
> way and if so how?
>
> I also am trying to pass a variable into a statement using a where like
> statement.
>
> I.E. sqlstmt ' delete from (variable array) where description like
> "%(variable)%" '
>
> I do not know the version of the Informix database although it is at
> least
> one or two years old. It is running on AIX 3.2 and UnixWare 2.03
>
> If anyone has any suggestions for me I will appreciate them.
> kirt_t@msn.com
>
>
>
Something like this might work
#!/bin/ksh
typeset -A TABNAME
let index=4
TABNAME[1]="fred"
TABNAME[2]="fred"
TABNAME[3]="fred"
TABNAME[4]="fred"
while [ ${index} -gt 0 ]
do
dbaccess <database> <<-EOF
delete from ${TABNAME[${index}]}
where pk = "%${variable}%";
EOF
let index=${index}-1
done
Posting you code would help though :-)
Paul Watson # I don't suffer from
WF Software Ltd. # stress, I'm just
Tel. (+44) 1436 674729 # a carrier
Fax. (+44) 1436 678693 #
www.wfsoftware.co.uk