Skip to Content

Fetch returns more than requested number of rows

Hi folks,

I'm passing a single field from a single row into a variable in a procedure. The following example works if MSEG query results in a single row;

EXAMPLE 1: lets say I have a one row in MSEG table;

Row1 MENGE: 100

select a.MENGE into OnHandQty from "MSEG" where condition = X

Result is OnHandQty = 100 << SUCCESS!!

EXAMPLE 2: lets say I have two rows in mseg table;

Row1 MENGE 100

Row2 MENGE 50

To handle multiple rows in the query I thought the following would work;

select sum(a.MENGE) into OnHandQty from "MSEG" where condition = X

I get error 'fetch returns more than requested number of rows'. Although if I run the SQL without attempting to insert into a variable I can clearly see the result is 1 single row result with value of 150.

Is aggregation not supported when using INSERT INTO VARIABLE in a procedure?

Thanks,

-Patrick

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    Posted on May 13, 2014 at 03:25 AM

    Hi Patrick,

    Your error sounds strange. May be you can paste your code.

    Following code works for me on Hana Rev 70.

    Thanks

    Sagar

    BEGIN

    DECLARE QUANTITY DECIMAL(15,2);

    SELECT SUM(MENGE) INTO QUANTITY FROM MSEG WHERE MJAHR < '2010';

    SELECT :QUANTITY FROM DUMMY;

    END;

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.