Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
36 views3 pages

Sap Hana SQL Quick Notes

The document provides a quick reference guide for SAP HANA SQL, covering SQL basics, data types, string and date functions, joins, case logic, aggregate functions, subqueries, table manipulation, views, procedures, analytic functions, and performance tips. Key SQL commands and examples are included for each topic. It emphasizes best practices for optimizing SQL queries in SAP HANA.

Uploaded by

manibpsc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views3 pages

Sap Hana SQL Quick Notes

The document provides a quick reference guide for SAP HANA SQL, covering SQL basics, data types, string and date functions, joins, case logic, aggregate functions, subqueries, table manipulation, views, procedures, analytic functions, and performance tips. Key SQL commands and examples are included for each topic. It emphasizes best practices for optimizing SQL queries in SAP HANA.

Uploaded by

manibpsc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

SAP HANA SQL Quick Notes

1. SQL Basics:

SELECT col1, col2

FROM schema.table

WHERE col1 = 'ABC'

GROUP BY col2

HAVING COUNT(*) > 1

ORDER BY col2 DESC

LIMIT 10 OFFSET 5;

2. Data Types:

- Numeric: INTEGER, BIGINT, SMALLINT, DECIMAL(p,s), DOUBLE

- Character: VARCHAR(n), NVARCHAR(n), ALPHANUM(n)

- Date/Time: DATE, TIME, SECONDDATE, TIMESTAMP

- Boolean: BOOLEAN (TRUE / FALSE)

3. String Functions:

LENGTH(str), LOWER(str), UPPER(str), TRIM(str),

SUBSTRING(str, start, length), INSTR(str, substr),

REPLACE(str, old, new), CONCAT(str1, str2)

4. Date Functions:

CURRENT_DATE, CURRENT_TIMESTAMP,

ADD_DAYS(date, n), ADD_MONTHS(date, n),

DAYS_BETWEEN(d1, d2), MONTHS_BETWEEN(d1, d2), TO_DATE(string, format)

5. Joins:

INNER JOIN, LEFT JOIN, RIGHT JOIN, FULL JOIN

Example:

SELECT A.*, B.*

FROM tableA A

LEFT JOIN tableB B ON A.id = B.id;


6. Case and IF Logic:

SELECT

CASE

WHEN col1 > 100 THEN 'High'

WHEN col1 > 50 THEN 'Medium'

ELSE 'Low'

END AS category

FROM table;

7. Aggregate Functions:

COUNT(*), SUM(col), AVG(col), MIN(col), MAX(col)

8. Subqueries:

SELECT name

FROM employees

WHERE salary > (SELECT AVG(salary) FROM employees);

9. Table Creation & Manipulation:

CREATE COLUMN TABLE my_table (

id INT PRIMARY KEY,

name NVARCHAR(100),

created_at DATE

);

INSERT INTO my_table VALUES (1, 'ABC', CURRENT_DATE);

UPDATE my_table SET name = 'XYZ' WHERE id = 1;

DELETE FROM my_table WHERE id = 1;

10. Views & Procedures:

CREATE VIEW my_view AS

SELECT col1, col2

FROM my_table

WHERE status = 'A';


CREATE PROCEDURE get_total (OUT total INT)

AS

BEGIN

SELECT COUNT(*) INTO total FROM my_table;

END;

11. Analytic Functions:

SELECT name, salary,

RANK() OVER (PARTITION BY department ORDER BY salary DESC) AS dept_rank

FROM employees;

12. CDS Views / HANA Views:

- CDS: Core Data Services (ABAP layer)

- HANA Views: Calculation / Analytic Views via HANA Studio or Web IDE

13. Performance Tips:

- SELECT only needed columns

- Filter early using WHERE

- Prefer INNER JOIN over OUTER JOIN

- Use Indexes on WHERE/GROUP BY columns

- Avoid SELECT * in production

You might also like