Skip to Content
0

HANA SQL - Multiple Aggregations in SELECT

Dec 12, 2016 at 06:53 PM

180

avatar image

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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
Florian Pfeffer
Dec 12, 2016 at 07:40 PM
2

You have to use just one "into" clause.

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