I think that there is, but I'm not near a DB2 system so can't experiment. Have you tried just using the MY_FIELD name in the GROUP BY, leaving off the 1,4 bit?
I found the answer on another board if anyone is interested:
SELECT Z.MY_ALIAS_NAME
,COUNT(*)
FROM (SELECT SUBSTR(MYFIELD,1,4) MY_ALIAS_NAME
FROM MYDATABASE_MYTABLE
WHERE STATE = '20'
AND GENERAL_STATUS = '1'
AND REASON_GENERAL = 'A') Z
GROUP BY Z.MY_ALIAS_NAME
A 'group by' on a substringed column is allowed, but you need to repeat the expression LITERALLY in the group by part. Anyway, this is indicated for DB2 UDB.
For mainframe / AS400 it may be another story....
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.