Re: Informix where clause - how to parameterize the column-name
Posted in 1991
Path: emory!swrinde!cs.utexas.edu!convex!texsun!letni!mic!ferus!alan
From: alan@ferus.lonestar.org (Alan Caldera)
Newsgroups: comp.databases
Summary: Assuming Informix-4GL..answer
Keywords: Informix
Message-ID: <1991Jun17.235947.787@ferus.lonestar.org>
Date: 17 Jun 91 23:59:47 GMT
References: <31474@hydra.gatech.EDU>
Organization: Logic Process Informix Hacks Therapy Group - Dallas
In article <31474@hydra.gatech.EDU>, gt8963a@prism.gatech.EDU (MCCARTNEY,JEFFREY ELWOOD) writes:
> I'm trying to parameterize the column-name in an Informix WHERE clause.
>
> Here's what I mean:
>
> SELECT * FROM customer WHERE col_var = NULL>
> ^^^^^^^
I'm assuming that you are refering to Informix-4GL in which case the following
maybe used:
LET sel_1 (a char variable) = "SELECT * FROM customer WHERE ",col_var_name,
" IS NULL "
PREPARE sel_stmt (some unique undefined var) FROM sel_1
Then you have 2 choices:
EXECUTE sel_stmt
-or-
DECLARE some_curs CURSOR FOR sel_stmt
FOREACH some_curs INTO some_record_var.*
I have found that this works very well, the only caveat being that when
dealing with numerics to first convert them into some sort of reasonable
char value first. (So that you can concatenate into the string.)
Remember also to put quotes around any string within the SELECT statement
Hope this helps
--alan
--------------------------------------------------------------------------
Alan Caldera/ 10610 Metric Rd/ Logic Process Corporation / Dallas, TX 75423
(214) 340-5172
#include <std.cute.disclaimer>