Hi
Can someone please advise how my function should be written to do the following;
I've got a table that I want to count records for that match an input key value and another criteria. If this count is <= 12 then another table value is to be read and returned, otherwise another table value is returned.
This is what I've got;
However, when I try to run this it complains about the variable SELECT not being defined and the keyword COUNT.
This is on a v5r4 machine.
Please advise?
Thanks
Can someone please advise how my function should be written to do the following;
I've got a table that I want to count records for that match an input key value and another criteria. If this count is <= 12 then another table value is to be read and returned, otherwise another table value is returned.
This is what I've got;
Code:
CREATE FUNCTION XCASHSETT/XGETDTETOL (PSIDIN INT) RETURNS INT LANGUAGE SQL DETERMINISTIC NO EXTERNAL ACTION READS SQL DATA RETURNS NULL ON NULL INPUT SET OPTION DBGVIEW=*SOURCE BEGIN DECLARE INSTCOUNT SMALLINT; DECLARE EXIT HANDLER FOR SQLSTATE VALUE '22007' RETURN NULL; SET INSTCOUNT = SELECT COUNT(*) FROM UPIZREP WHERE IZITTY='INST' AND IZRCFD='' AND IZPSID=PSIDIN; IF INSTCOUNT <= 12 THEN RETURN SELECT DCVALU FROM UCDTREP WHERE DCNAME='XCSDTETOL1'; ELSE RETURN SELECT DCVALU FROM UCDTREP WHERE DCNAME='XCSDTETOL2'; ENDIF; END
This is on a v5r4 machine.
Please advise?
Thanks
Comment