Re: How do I replace variables in sql with data from file ?????
Posted in 1994
From Bonnie Weller:
* I need some programming advice. I am using a SUN OS 4.1.3
* I have Informix SE 5.01, SQL 4.11
* I am unsure how to read information from a data file into a sql file
* containing variables.
*
* What I want to do is read in fields 1, 2 and 4 from "tempa" file into the
* "scripts.sql file", replacing variables with certain fields from the "tempa"
* file. Field 1 is to replace variable &easting, field 2 is to replace variable
* &northing and field 3 is to replace &radius. (pipe is the delimiter) What
* the sql script does is it reads in UTM data from the "tempa" file and finds
* all records that fall with a given radius of that point. Ultimately, these
* results will be outputted to a report using ACE (I'm not that far yet :-))
<< STUFF Deleted >>
Here is one way to do what you want from the command line. Put the following
into a shell script and execute it. It will put it's output into the file
species.out.
# --v-- SNIP --v-- SNIP --v-- SNIP --v-- SNIP --v-- SNIP --v-- SNIP --v--
# species.sh
cat tempa | tr "|" " " | while read easting northing f3 radius rest
do
isql spcs_loc >> species.out 2>/dev/null <<EOSQL
select * from sites where
( ( ( easting - ${easting} ) * ( easting - ${easting} ) +
( northing - ${northing} ) * ( northing - ${northing} )
) < ( ${radius} ) * ( ${radius} )
)
AND easting > 0 AND northing > 0;EOSQL
done
# --^-- SNIP --^-- SNIP --^-- SNIP --^-- SNIP --^-- SNIP --^-- SNIP --^--
Hope this helps,
Robert Minter |Data Systems Support| \\\\\\_///
Programmer, Software Development | Orange, CA | ( _ _ )
internet: rob@dssmktg.com | Tel: 714.771.0454 | (| ^ |)
bangpath: uunet.uu.net!dssmktg!rob| Fax: 714.771.3028 | \\`-'/
#include <disclaimer.h> SURF'S UP \\_/