Skip to Content

HANA SQL - Multiple Aggregations in SELECT

Hi,

I want to know if we can pass multiple aggregation functions values to variables in a single SELECT statement.

Here's a sample code on a test table, similar to the actual code that fails with the same error,

insert into <table> values(11,'lox'); 

insert into <table> values(12,'pox'); 
insert into <table> values(13,'sox'); DO (OUT mini INT => ?, OUT maxi INT => ?) BEGIN Select MIN("id") into mini, MAX("id") into maxi from "PUBLIC"."HEADERTAB"; END Error: Could not execute 'DO (OUT mini INT => ?, OUT maxi INT => ?) BEGIN Select MIN("id") into mini, MAX("id") into maxi ...' in 3 ms 688 µs . SAP DBTech JDBC: [257]: sql syntax error: incorrect syntax near "(": line 3 col 30 (at pos 81) But the below statement works: Select MIN("id") as "mini", MAX("id") as "maxi" from "PUBLIC"."HEADERTAB"

I am doing this in a procedure and trying to pass the minimum and maximum values into a variable. Right now I am doing at two separate SELECTs.

Thank You,

Benedict

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Dec 12, 2016 at 07:40 PM

    You have to use just one "into" clause.

    SELECT min("id"), max("id") INTO mini, maxi from "PUBLIC"."HEADERTAB";
    Add comment
    10|10000 characters needed characters exceeded