Hi, I provide training in SAP UI5. Also feel free to checkout my new web page https://saptechblog.com
SAP HANA

Introduction to Basic SQL Statements

 

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.

clip_image002

 

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.

clip_image004

 

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:

clip_image006

 

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:

clip_image007

 

Result:

clip_image009

 

 

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:

clip_image010

Result:

clip_image011

 

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:

clip_image012

Result:

clip_image013

 

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:

clip_image014

 

Result:

clip_image016

 

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:

clip_image017

 

Result:

clip_image018

 

 

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:

clip_image019

 

Result:

clip_image020

 

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:

clip_image021

Result:

clip_image022

 

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:

clip_image023

 

Result:

clip_image024

 

 

 

About Arun

0 Comments:

Post a Comment

Powered by Blogger.