SAP HANA IF Statement Using AND and OR example
TEMP_TABLE DATA
-----------------------
ID NAME AGE
--- --------- ---
1 PETER
23
2 DANIEL
45
3 ROSEMARY
22
4 ELISA
26
5 PAUL
36
6 GARY
39
7 JOHN
41
10 PETER 29
--------------------
DO BEGIN
DECLARE vi_id BIGINT;
DECLARE vi_cnt INT;
DECLARE vi_age
BIGINT;
DECLARE VS_NAME
VARCHAR(700) := '';
DECLARE VS_MESS
VARCHAR(700) := '';
DECLARE CURSOR
c_tb_table FOR SELECT id, name, age FROM TEST_TABLE;
vi_id := 1;
FOR cur_row as
c_tb_table DO
vi_cnt := vi_cnt +
1;
IF ( (LEFT(cur_row.name,1) = 'P' AND
SUBSTRING(cur_row.name,2,1) = 'A'
)
OR
(SUBSTRING(cur_row.name,1,4)
= 'ROSE')
OR
(
LEFT(cur_row.name,1) = 'E' AND RIGHT(cur_row.name,1) = 'A' )
THEN
VS_MESS :=
cur_row.name ||', '|| VS_MESS;
END IF;
END FOR;
select VS_MESS col3
from dummy;
END