This is a quick blog post to show a nifty place to store code snippets in HANA Studio. I’m thinking of snippets that you execute often and lose somewhere in your HANA Studio tabs, the ones where you haven’t been super diligent about saving as sql files. (Confession time, this is me, I have useful code snippets stored in lots of random places that seemed like a good place at the time. 😉 )
Note: I know HANA Studio is “dead” with HANA 2.0, however many people are still using it and are still using HANA XS Classic, so perhaps this tip will help someone have a nicer experience in the client tool.
This is also the same spot where you can upload the helpful sql zip file that SAP provides as per “SAP Note 1969700 – SQL statement collection for SAP HANA”. I’m not going to go through those steps now as they are already nicely covered in the following blog:
Using the same concept we’re also able to store our own SQL snippets, here are the steps:
Step 1: Double-click on any system in HANA Studio and then navigate to the “System Information” tab
Step 2. Right-click in the open area and select “New SQL Statement”
Step 3: Give your script a name and description and paste your code in. It must start with SELECT or WITH.
Step 4: You can save using top menu, it will then be available on all systems you’ve configured in HANA Studio and you do not have to repeat the steps per system
Step 5: Your script will now be available on the “System Information” tab.
Step 6: Right-click and select “Execute” to run it
Step 7: The results will be displayed in a data preview screen
Step 8: You can also open the script in the SQL Console by right-clicking and selecting “Open in SQL Console”, perhaps if you want to edit it before executing
Tip: If you perhaps want to store script that doesn’t start with SELECT or WITH :
Then you can just fool it with a dummy select statement followed by your script. It won’t execute if you call the “Execute” function as this is expecting a single result, however you can still open it with SQL Console and execute from there
Good luck getting organized. 🙂