0

My Function is getting a error but I don't know why ...

MY (DB2)SQL CODE:

CREATE FUNCTION gibX(sseries INTEGER, idd INTEGER) RETURNS Double
 BEGIN
   Declare result Double;
   SELECT ROW_NUMBER() OVER(ORDER BY m.x ASC) AS Row, m.x  INTO result 
   FROM messungen m WHERE m.series=sseries and Row=idd;
   return result;
 END;

ERROR:

CREATE FUNCTION;
   return result;
;, DRIVER=4.13.80

... and passed successfully.

1 Answer 1

1

You cannot reference row in the where. One method is a subquery:

SELECT x INTO result
FROM (SELECT ROW_NUMBER() OVER (ORDER BY m.x ASC) AS Row, m.x  
      FROM messungen m
      WHERE m.series = sseries
     ) m
WHERE Row = idd;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.