-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

My old eyes are getting a little weak, but I don't see SQREQ in the list
of columns in the result set. My understanding is that HAVING runs
against the result set. What happens if you use openS0 and ordqty in the
HAVING clause? If that doesn't work, try including sqreq, sqfin, lqord
and lqshp in the result set. I'm 87.3% certain that will work.

On 2011-02-03 18:57, Pete Helgren wrote:
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 Hall
pete@xxxxxxxxxxxxxx
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iEYEARECAAYFAk1LXkAACgkQXczQcKdXKg6kfACeKQ/eFreI0BQ5MqvFLseQ3XFp
LXoAniA9ux+shLcQi8EOcfhHBBgj5Uho
=qx8q
-----END PGP SIGNATURE-----

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.