cancel
Showing results for 
Search instead for 
Did you mean: 

How to execute a SQL statement from a Table in SAP HANA.

former_member184871
Contributor
0 Kudos

Hello Community,


Refer to screen-shot for table structure.

I have to create a stored procedure with an input parameter as USER_INPUT which will be checked with "TEXT" - when User Input matches the data stored in the TEXT then the corresponding query should get executed.

Please guide me how to achieve the same.

Regards

Kumar

Accepted Solutions (1)

Accepted Solutions (1)

former_member182302
Active Contributor
0 Kudos

You got to use EXEC or EXECUTE IMMEDIATE to achieve it.

When the user input matches, the corresponding query should be taken into a String variable.

Example:

SQL_STRING := 'Select Count(*) from TABLE'

EXECUTE IMMEDIATE (:SQL_STRING)

Have a look on the sample proc created using EXECUTE IMMEDIATE below.

Regards,

Krishna Tangudu

former_member184871
Contributor
0 Kudos

Hi Krishna

Thanks for the reply. when I am executing the procedure, I am getting the output as :

But the expected output is the total no of records present in the table !!

Following is the code I used :

I think I am missing something !!

Please guide.

Regards

Kumar

sergey_sheremet
Explorer
0 Kudos

Hi Kumar,

Try the following statement

select "QUERY" into SQL_STR from "TA"."QUERYTABLE";

instead of SQL_STR := '...

Good luck!

WBR,

Sergey.

former_member182302
Active Contributor
0 Kudos

Hi Kumar,

You are executing the below query:

SELECT "QUERY" from "TA"."QUERYTABLE" and hence you are getting the corresponding output.

Change the code as mentioned below:

SELECT "QUERY" INTO SQL_STR FROM "TA"."QUERYTABLE" ;

EXECUTE IMMEDIATE (:SQL_STR);

Regards,

Krishna Tangudu

Former Member
0 Kudos

This message was moderated.

Answers (1)

Answers (1)

former_member184871
Contributor
0 Kudos

Thanks Krishna and Sergey