× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



There are a couple of reasons I haven't headed that direction. If I put them in the select then the 'group by' will also have to have them and since they will most likely be discreet values, my totaling logic will be lost. Somehow, referencing them in the select as I have, even though they are part of a result field calculation, satisfied the requirement because when I run the statement without the extra parens in the 'having' clause, it runs without error. I would have expected SQL to complain about the missing SQREQ under both scenarios. It only complains when I have the extra parens. Kinda weird. I might give Joe's CTE approach a whirl as I was leaning that way initially.

Pete Helgren
Value Added Software, Inc
www.asaap.com
www.opensource4i.com


On 2/3/2011 7:02 PM, Pete Hall wrote:
-----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 ...

Replies:

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.