cancel
Showing results for 
Search instead for 
Did you mean: 

EXEC in SAP HANA

karthik1993
Participant
0 Kudos
782

Hi Experts,

Is there a way to store intermediate results that gets generated out of EXEC command into a temp table in SAP HANA SQL? I understand that we can use INTO to store single value result but i'm expecting tabular result and I really need to have EXEC command inside my code as the Stored Procedure is running Dynamically by fetching data from different tables.

Ex:

EXEC 'select column1, count(column1) from table 1 group by column1'

Thanks

Accepted Solutions (1)

Accepted Solutions (1)

RobertWaywell
Product and Topic Expert
Product and Topic Expert

You can use an INSERT INTO SELECT... statement. Here is an example.

DROP TABLE T1;


DROP TABLE T2_AGGREGATE_OF_T1;


CREATE TABLE T1
(	COL1	INT PRIMARY KEY,
	COL2	CHAR(10)
);


CREATE  TABLE T2_AGGREGATE_OF_T1
(	COL1		CHAR(10) PRIMARY KEY,
	COUNT_COL1	INT
);




INSERT INTO T1 VALUES (1, 'Red');
INSERT INTO T1 VALUES (2, 'Blue');
INSERT INTO T1 VALUES (3, 'Green');
INSERT INTO T1 VALUES (4, 'Red');
INSERT INTO T1 VALUES (5, 'Blue');
INSERT INTO T1 VALUES (6, 'Red');


DO BEGIN


EXEC 'INSERT INTO T2_AGGREGATE_OF_T1 SELECT T1.COL2, COUNT(T1.COL2) FROM T1
GROUP BY COL2';


END;


SELECT * FROM T1;


SELECT T1.COL2, COUNT(T1.COL2) FROM T1
GROUP BY COL2;




SELECT * FROM T2_AGGREGATE_OF_T1;


karthik1993
Participant
0 Kudos

Thanks a lot

Answers (0)