- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Sort data in SQL using Dynamic SQL in SAP HANA
In order to execute dynamic SQL in your stored procedure, you need to use the ‘EXECUTE IMMEDIATE’ statement. You can use SQL as shown below to execute it:
EXECUTE IMMEDIATE 'SELECT <COLUMN NAMEs> FROM <TABLE NAME> ' || :<ORDERING COLUMN> || ' DESC';
Another thing to notice over here is that if you are planning to use the table type in the final select statement with dynamic SQL, it will not work. Dynamic SQL does not support table type in select. What you can try as a work around is that you can dump the data in a temporary table before using it in the dynamic SQL and then use a temporary variable in the SQL.
Advertisements