SELECT ..., BITOR(0,myfield) ..It would need to store the intermediate in pnResult like
pnResult = 0 SELECT FUNCTION BITORSQL(tnVal) pnResult =BITOR(pnResult , tnVal) RETURN pnResultand to reset pnResult for each unifier (e.g. group), see below
pnResult = 0 pnLastUni = 0 SELECT i1,BITORSQL(i2,i1) FROM muh GROUP BY 1 FUNCTION BITORSQL(tnVal,tnUni) IF tnUni#pnLastUni THEN pnLastUni = tnUni pnResult = 0 ENDIF &&tnUni#pnLastUni pnResult =BITOR(pnResult , tnVal) RETURN pnResult ENDFUNC &&BITORSQL(tnVal,tnUni)I get something, bot a closer look shows that the function will not be called for every record in the source
pnResult = 0 pnLastUni = 0 SELECT; Cur1.i1,; (SELECT MAX(BITORSQL(cur2.i2,cur2.i1)) AS i2 FROM muh AS cur2 WHERE cur2.i1=cur1.i1) AS i2; FROM muh AS cur1; GROUP BY 1 FUNCTION BITORSQL(tnVal,tnUni) IF tnUni#pnLastUni THEN pnLastUni = tnUni pnResult = 0 ENDIF &&tnUni#pnLastUni pnResult =BITOR(pnResult , tnVal) RETURN pnResult ENDFUNC &&BITORSQL(tnVal,tnUni)and unbelievably it works. MAX is ok, I will not use bit 31 anyway.
LOCAL; lnResult,; lnLastUni STORE 0 TO; lnResult,; lnLastUni SELECT; Cur1.i1,; (SELECT MAX(BITORSQL(cur2.i2,cur2.i1,@lnResult,@lnLastUni)) AS i2 FROM muh AS cur2 WHERE cur2.i1=Cur1.i1) AS i2,; sum(i2); FROM muh AS Cur1; GROUP BY 1 FUNCTION BITORSQL(tnVal,tnUni,tnResult,tnLastUni) IF tnUni#tnLastUni THEN tnLastUni = tnUni tnResult = 0 ENDIF &&tnUni#tnLastUni tnResult =BITOR(tnResult , tnVal) RETURN tnResult ENDFUNC &&BITORSQL(tnVal,tnUni)BTW the subquery seems to be identified as aggregate. I have SET ENGINEBEHAVIOR 80 and GROUP BY is only row 1, but all runs fine. Mayby not because GROUP BY 1,2 changes nothing.
>pnResult = 0 > >SELECT ..., BITORSQL(myfield) ... > >FUNCTION BITORSQL(tnVal) >RETURN BITOR(pnResult , tnVal) >>