I am trying to run a SQL query as follows:
SELECT INVMST.INUMBR, INVMST.IDESCR,
CASE WHEN SUM(INVCHS.CHQT01) = 0 THEN SUM(INVCHS1.CHQT01) ELSE
SUM(INVCHS.CHQT01) END as QTY1,
CASE WHEN SUM(INVCHS.CHQT02) = 0 THEN SUM(INVCHS1.CHQT02) ELSE
SUM(INVCHS.CHQT02) END as QTY2,
SUM(QTY1+QTY2) as SUMQTY FROM ............etc
The actual query uses QTY3 through QTY12 with CASE statements as
well, I just chopped it down a bit for readability. My question is how
do I add a field to the query resutls that is the SUM of QTY+QTY2+...
+QTY12? The QTYX values are dependent on case statements for their
assigned values. The SUM(QTY1+QTY2+QTY3+etc.) statement gives an
error:
SQL0206 - Column QTY1 not in specified tables.
Cause ...... : QTY1 is not a column of table *N in *N, QTY1 is not a
column of any table or view that can be referenced. (etc.)
What is the correct SQL query way to return a field that is the SUM
of QTY1 through QTY12?
Thanks for any help!!
ASM