Pete,
I know this can work if the same expression in your having clause is among the selects and among the group by. Would this do what you want?
select ixprod,ixdesc,extvin,(lqord-lqshp) as ordqty,
coalesce(sqreq-sqfin,0) as openSO,
((coalesce(sqreq-sqfin,0)) - (lqord-lqshp)) as diffqty
from fix inner join ecl on ixprod=lprod
inner join eclx01 on lord=extord and lline=exline left outer join fso on ixprod=sprod group by ixprod,ixdesc,extvin, (lqord-lqshp),
coalesce(sqreq-sqfin,0),
((coalesce(sqreq-sqfin,0)) - (lqord-lqshp))
having ((coalesce(sqreq-sqfin,0)) - (lqord-lqshp)) > 0
-----Original Message-----
From: midrange-l-bounces@xxxxxxxxxxxx [mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of Pete Helgren
Sent: Thursday, February 03, 2011 6:58 PM
To: Midrange Systems Technical Discussion
Subject: Issue with an SQL having clause
I need to select records where the total of some fields is greater than zero. The field comparisons are from two different tables. Here is the
sql:
select ixprod,ixdesc,extvin,(lqord-lqshp) as ordqty,
coalesce(sqreq-sqfin,0) as openSO
from fix inner join ecl on ixprod=lprod
inner join eclx01 on lord=extord and lline=exline left outer join fso on ixprod=sprod group by ixprod,ixdesc,extvin, (lqord-lqshp),
coalesce(sqreq-sqfin,0)
having ((coalesce(sqreq-sqfin,0)) - (lqord-lqshp)) > 0 <---- It doesn't like this line
I am running this in an interactive SQL session to test it and it is complaining about the SQREQ column in the having clause.
This DOES work:
select ixprod,ixdesc,extvin,(lqord-lqshp) as ordqty,
coalesce(sqreq-sqfin,0) as openSO
from fix inner join ecl on ixprod=lprod
inner join eclx01 on lord=extord and lline=exline left outer join fso on ixprod=sprod group by ixprod,ixdesc,extvin, (lqord-lqshp),
coalesce(sqreq-sqfin,0)
having coalesce(sqreq-sqfin,0) > 0
Yet with addition of one set of parenthesis in the having clause, it will stop working:
select ixprod,ixdesc,extvin,(lqord-lqshp) as ordqty,
coalesce(sqreq-sqfin,0) as openSO
from fix inner join ecl on ixprod=lprod
inner join eclx01 on lord=extord and lline=exline left outer join fso on ixprod=sprod group by ixprod,ixdesc,extvin, (lqord-lqshp),
coalesce(sqreq-sqfin,0)
having (coalesce(sqreq-sqfin,0)) > 0 <-----This will not work.
The reason for the parens is so that the having clause is properly evaluated, but I must be doing something wrong.
What am I missing?
--
Pete Helgren
Value Added Software, Inc
www.asaap.com
www.opensource4i.com
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list To post a message email: MIDRANGE-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit:
http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx Before posting, please take a moment to review the archives at
http://archive.midrange.com/midrange-l.
As an Amazon Associate we earn from qualifying purchases.