Quantcast
Channel: SCN : Discussion List - SAP HANA and In-Memory Computing
Viewing all articles
Browse latest Browse all 5653

How to get the result of the stored procedure within the stored procedure

$
0
0

Hi All,

 

Our applications runs on dynamic query ( selected columns , and inner join table will be varying depending upon the user selection).

 

I am creating HANA store procedure to get the previous, previous ..previous change columns ( history - based on the columns) of the row  for the columns specified by the user ( no. of columns will be again depend on the user selection and comparison type could be 'AND' , 'OR'  or both AND & OR).

 

To achieve this functionality I am creating a stored procedure in HANA and I am very new to HANA DB.

 

Can some one tell me how can I achieve the below functionality in  HANA Stored Procedure.

 

1. NVARCHAR(MAX) in HANA , because my dynamic sql script is really very big and I cannot use the BLOB data type since  I need to dynamically add some columns into query to achieve my functionality.

 

2. How to get the result from the Stored procedure within the store procedure ( I cannot create a temporary table in this case , because my select columns will vary ) , so that I can start processing my result set to achieve the desired output

 

SAMPLE SCRIPT

CREATE PROCEDURE ChangeResultSql(IN QUERY NVARCHAR(50000),IN ChangeRequestPaarameter NVARCHAR(5000),IN ChangeRequestOperator VARCHAR(100)) LANGUAGE SQLSCRIPT AS
BEGIN

DECLARE sqlquery VARCHAR(50000);
DECLARE userId VARCHAR(100);

sqlquery := 'WITH Sample AS (' || QUERY || '),Sample1 As (SELECT *, CostCenterLabel || '','' || EvenReasonIcode AS COMPARISON_COLUMN , ROW_NUMBER() OVER (PARTITION BY UserSysID ORDER BY EffectiveStartDate DESC ) AS RowNUM from Sample ORDER BY UserSysID
,EffectiveStartDate DESC)  Select * from Sample1 ';

--Select * from  :sqlquery;
output_table = CALL "AMWAY_TRAD_2_1505_ROTS_04052015"."CHANGERESULT"(:sqlquery);

BEGIN
  DECLARE CURSOR user_cursor FOR SELECT UserSysID From output_table group by UserSysID ORDER BY UserSysID;
  OPEN user_cursor;
  FETCH user_cursor into userId;
  CLOSE user_cursor;
END;

 


END



 

 

Thanks,

Hemapriya


Viewing all articles
Browse latest Browse all 5653

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>