Subject | why won't this query work |
---|---|
Author | Dixon Epperson |
Post date | 2004-11-23T19:46:19Z |
This query gets the error message
"Invalid expression in the select list (not contained in either an
aggregate function or the GROUP BY clause) . . ."
SELECT c1.CO_IDNUM, c1.CO_NAME,
(SELECT SUM(s2.SA_TOTAL)-
(SELECT SUM(y1.YD_AMTAPLD) FROM PAYDETAIL y1 JOIN PAYREGISTER r1 ON
(y1.YD_NUM=r1.PY_NUM)
WHERE (y1.YD_INV=s2.SA_INVOICE AND y1.YD_VOID='0' AND r1.PY_DATE <=
'11/23/04'))
FROM SALESREG s2 WHERE (s2.SA_INVDATE > '10/23/04') AND
s2.SA_VOID='0' AND s2.SA_CUSTID = c1.CO_IDNUM),
FROM SALESREG s1 LEFT JOIN COMPANY c1 ON (s1.SA_CUSTID = c1.CO_IDNUM)
GROUP BY c1.CO_NAME, c1.CO_IDNUM order by c1.co_name
The problem comes when I add this second part
"-
(SELECT SUM(y1.YD_AMTAPLD) FROM PAYDETAIL y1 JOIN PAYREGISTER r1 ON
(y1.YD_NUM=r1.PY_NUM)
WHERE (y1.YD_INV=s2.SA_INVOICE AND y1.YD_VOID='0' AND r1.PY_DATE <=
'11/23/04'))"
I've tried moving it outside the first sub select, but then I can't
see the s2 table,
Would appreciate some help on this,
Dixon Epperson
"Invalid expression in the select list (not contained in either an
aggregate function or the GROUP BY clause) . . ."
SELECT c1.CO_IDNUM, c1.CO_NAME,
(SELECT SUM(s2.SA_TOTAL)-
(SELECT SUM(y1.YD_AMTAPLD) FROM PAYDETAIL y1 JOIN PAYREGISTER r1 ON
(y1.YD_NUM=r1.PY_NUM)
WHERE (y1.YD_INV=s2.SA_INVOICE AND y1.YD_VOID='0' AND r1.PY_DATE <=
'11/23/04'))
FROM SALESREG s2 WHERE (s2.SA_INVDATE > '10/23/04') AND
s2.SA_VOID='0' AND s2.SA_CUSTID = c1.CO_IDNUM),
FROM SALESREG s1 LEFT JOIN COMPANY c1 ON (s1.SA_CUSTID = c1.CO_IDNUM)
GROUP BY c1.CO_NAME, c1.CO_IDNUM order by c1.co_name
The problem comes when I add this second part
"-
(SELECT SUM(y1.YD_AMTAPLD) FROM PAYDETAIL y1 JOIN PAYREGISTER r1 ON
(y1.YD_NUM=r1.PY_NUM)
WHERE (y1.YD_INV=s2.SA_INVOICE AND y1.YD_VOID='0' AND r1.PY_DATE <=
'11/23/04'))"
I've tried moving it outside the first sub select, but then I can't
see the s2 table,
Would appreciate some help on this,
Dixon Epperson