cancel
Showing results for 
Search instead for 
Did you mean: 

Using : before variable in procedures

Former Member
0 Kudos

Hello All,

I have a question related to the use of ":" before variables in procedures,

i highlighted some of the variables in the example below, do we need to use ":" before these variables and when we have to use them and when we should not and how can it affect the result.

For example :

CREATE PROCEDURE DUMMY

LANGUAGE SQLSCRIPT AS

BEGIN

            DECLARE a, d, i INT;

            DECLARE b INT = 0;

            DECLARE c INT DEFAULT 0;

            DECLARE n VARCHAR(20) DEFAULT 'this code is junk';

            CREATE GLOBAL TEMPORARY TABLE TBL (COL INT);

            FOR i in 1..3 DO

                        INSERT INTO TBL VALUES (:i);

                        BEGIN

                                   DECLARE d INT;

                                   b = (😛 + 1) * 6;

                                   c = :i;

                        END;

            END FOR;

            t = SELECT * FROM TBL;

            SELECT COUNT(*) INTO a FROM :t;

            b = 😛 + :a + 1;

            d = MONTH(CURRENT_DATE);

            IF :d > 6

            THEN

                        c = :c + 1;

            ELSE

                        c = :c + 2;      

            END IF;

END;

Thanks

Accepted Solutions (0)

Answers (1)

Answers (1)

lbreddemann
Active Contributor
0 Kudos

That's explicitly mentioned in the SQLscript reference!


If you want to access the value of the variable, then use :var

in your code.

If you want to assign a value to the variable, then use var in your code

Check the documentation that comes with your SAP HANA studio (F1!):

SAP HANA SQLScript Reference > Imperative SQLScript Logic

Local Scalar Variables

- Lars

Former Member
0 Kudos

It's Clear Now Thanks