Knowledge on SQL and SQL Script is necessary for one to work with HANA. This tutorial explains Basic SQL statements: It explains the different addition of select statement and keywords.
Getting started:
We will choose one schema where we have sufficient privileges to execute the query to get the data.
Open the HANA studio à HANA Systems perspective. Choose the schema of your choice and open the SQL Console. Execute the below SQL Statement to check if you have sufficient privilege to that schema.
After choosing the schema, for which you have sufficient privilege we will write SQL Statements to fetch data from the table of this schema.
A Simple select statement
We will write a simple SQL statement to fetch the contents of Business partner table in the SAP_HANA_DEMO Schema.
In this select statement we are picking all the records from the database table Business partner. For the from clause we have specified to the path of the table which is “Schema”.“Table Name”
You can drag and drop the table from the schema into the SQL Editor to Generate the path for table name.
Result:
Top 10 records
This Statement is similar to that of Select up to in ABAP Open SQL. We specify the keyword top to fetch the limited no of data requested from the top of the table.
Query:
Result:
Select Only specific columns
In the previous statement we have selected all the columns of the table using the field list *. Now if we want only specific columns to be displayed then the required columns have to be provided in the Select statement.
Query:
Result:
Using where clause
Now if we wanted only specific set of data, then we use the where clause to specify the conditions.
Say, you wanted to display data’s only when the currency is EUR.
Query:
Result:
Multiple conditions using AND
Similarly we can provide multiple conditions to the select statements, based on which it has to retrieve the data using AND addition.
Query:
Result:
Either or Conditions using OR
Data’s can also be fetched from the database table with either or conditions using the keyword ‘OR’.
Say for example, now if you wanted to fetch data where the currency is either Euro or USD.
Query:
Result:
Using In
Instead of using multiple or conditions to specify the data which the system has to pick we can create a dataset and instruct the system to pick the data when the conditions satisfy with the values in the dataset.
Query:
Result:
Using Like in where clause
If you wanted to pick up the data from the table with the pattern then you can use the keyword like in addition to the where clause.
Say for example, if you wanted to pick the data where the email id starts with letter ‘B’.
Query:
Result:
Range using where clause
You can also pick the data based on ranges. For which you have to use the addition between and to specify the from and to range to the where clause.
Say for example you wanted to display partner, where partner number ranging from 100000001 to 100000005
Query:
Result:
0 Comments:
Post a Comment