cancel
Showing results for 
Search instead for 
Did you mean: 

Can we pass a columns dynamically in the select statement of Calculation view.

0 Kudos

I am looking for an approach where I need to pass the table columns dynamically.

I have a table with below structure.

Table name: TABLE_COLUMNS

USERID | COLUMNA | COLUMNB | COLUMNC|

---------------------------------------------------------------------

A          |    10           |    20           |        30

B          |    11           |     21          |        31

C          |    12           |     22          |        32

I have a CV created with an input parameter which accepts a 'column' from above table. Based on the input parameter recieved, I need to display the values of the column.

Eg: If the input parameter recieves 'COLUMNA' as input, then I need to display the values from COLUMNA.

Can any one help me with the query which I need to script in the Calculation view. Normally in SQL console, I can write as

SELECT DISTINCT COLUMNA FROM TABLE_COLUMNS.

But this doesn't work in the Calculation view. Can anyone post the query I can use or an approach I can use.

Accepted Solutions (0)

Answers (2)

Answers (2)

former_member185511
Active Participant
0 Kudos

If the input parameter recieves 'COLUMNA' as input, then I need to display the values from COLUMNA.


why you dont use dynamic sql ? You can send column names dynamically

EXEC 'SELECT' ||:colname|| 'from CALC_VIEW'.


pfefferf
Active Contributor
0 Kudos

Really, you recommend to use dynamic SQL for that case with the known disadvantages? From my point it is not really necessary, also not in a scripted view.

Sometimes I miss a "dislike" button here .

former_member185511
Active Participant
0 Kudos

lol we don't know how many records or columns will be read or the real requirement here. why not use if that option is avaliable . we can't simply skip a solution due to disadvatanges

pfefferf
Active Contributor
0 Kudos

Hello Venkat,

are you using a graphical calculation view? In case you do and in case the type of your "dynamic" columns is the same, you can create a calculated column which uses the "case" function (Miscellaneous Functions - SAP HANA Modeling Guide - SAP Library).

e.g. CASE("$$IP_COL_NAME$$", 'COLUMNA', "COLUMNA", 'COLUMNB', "COLUMNB", 'COLUMNC', "COLUMNC")

Regards,

Florian