From your queries, I assume that you are fairly new to DB2 SQL. I, and probably most users of this forum, find that the best information to read is in the SQL cookbook by Graeme Birchall.
A Google search for 'Graeme Birchall' will find it.
Interestingly enough, I am not new to the SQL programming language. I am new to the DB2 syntax. When I tried adding a simple sum() function on a field, I get errors. Here it is....(I am having a hard time understanding the error handling that the ISeries returns.)
[IBM][iSeries Access ODBC Driver][DB2 UDB]SQL0122 - Column BPKQCD or expression in SELECT list not valid.
SQL = "SELECT BPKQCD as Unit, BPKRCD as Nature, sum(BSBEVA) as Budget, sum(BPBAVA/100) as Actual, BPGDNB, sum((BSBEVA-(BPBAVA/100)))as Variance, AHADNA FROM YABPREP LEFT OUTER JOIN YABSREP ON BPKQCD = BSJ6CD AND BPKRCD = BSJ7CD and BPGDNB=BSNBCD INNER JOIN YAAHREP ON BPKRCD = AHAFCD"
I wasn't implying a lack of SQL knowledge, just the vaguaries/specifics for DB2.
Your latest problem is that, as soon as you include an aggragate function such as SUM or COUNT in a query, you must add a GROUP BY clause, containing all non-aggragate fields - in this case:
GROUP BY
BPKQCD,BPKRCD,BPGDNB,AHADNA
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.