How to get a Boolean Expression in ACE
Posted in 1993
(Sorry if this is a repost... I don't think the last one went
out, but I might be wrong!)
I'd like to get a boolean expression in a select statement. I found
a kludgey way to do it, but it's not pretty. Am I missing some obvious,
clean way of doing this?
What I want to do is split a report into two parts, one with all data
that satisfies a condition, and the other with the data that doesn't.
Conceptually, what I want is something like this:
select amount, date_created > $end_date ind
from payments
order by ind;
before group of ind
if ind then
print "Payments after ", $end_date
else
print "Payments on or before ", $end_date
etc. I'd like to have "date_created > $end_date" be considered an
expression (like it is in C and lisp and most other languages), and
evaluate to a value (that I call ind). Unfortunately, sql doesn't
think that ">" is an operator that you can use in an expression: it's
a rel-op that can't be used in an expression.
I figured out an ugly way around it. It works, but it's inefficient
(it makes for a lot of extra processing, and there's a risk of the data
changing between the two selects). Here's what I do:
select rowid id
from payments
where date_created > $end_date
into temp kludge;
select payments.amount, payments.id - kludge.id ind
from payments, outer kludge
where payments.rowid = kludge.id
order by ind;
before group of ind
...
And voila`, ind is now a variable that contains NULL whenever
payments.date_created <= $end_date, and 0 if it's >.
This works in my application, but theres gotta be a better way!
If you know of one, please post.
Does anyone know why rel-ops aren't allowed in SQL expressions
in Informix? Most of the rest of the world is happy enough
with that. Was this exclusion the idea of Informix, or is it
part of The Standard?
--
Bill Foote bill@pds.com
PDS Corp, Los Angeles, CA USA uunet!promdist!bill
--
Bill Foote bill@pds.com
PDS Corp, Los Angeles, CA USA uunet!promdist!bill