An old dbf have been succesfully ODBC-connected to Excel (2010). The following SQL query (through Microsoft Query) works as expected giving a single result.
Microsoft Query (Excel 2010) code
SELECT c.NDELNUM AS deliverynote, SUM(c.NQTY*a.CPREDEF2) AS Total
FROM DelCusL AS c, Article AS a
WHERE c.CREF = a.CREF AND ((c.NDELNUM=?))
GROUP BY c.NDELNUM
I am interested in getting also single value, but the following retuns NULL:
SELECT c.NDELNUM AS deliverynote, SUM(c.NQTY*(a.CPREDEF2+c.CPROP2)) AS Total
FROM DelCusL AS c, Article AS a
WHERE c.CREF = a.CREF AND ((c.NDELNUM=?))
GROUP BY c.NDELNUM
I guess this does not work because empty values are encountered in either a.CPREDEF2 or c.CPROP2. When an empty value is encounterd, I'd like it to be treated as 0. I have tried casting value functions available in Microsoft Query to not much avail.
Any idea on converting EMPTY values to 0s so that the operation is successful?
NQTY is a number and always non-empty. CPREDEF2 is treated as VARCHAR and can be EMPTY: when EMPTY it seems to be treated as NULL from other tests; CPROP2 is an alternative value to CPREDEF2 and can also be EMPTY, if filled it can be understood as number(like CPREDEF2). Both CPREDEF and CPROP2 are treated as VARCHAR rather than numerical values but when on their own are correctly multiplied and aggregated as numbers. (It fails when I try to add them together before the aggregate function).