Skip to Content
-1

How to assign a variable to the result of a query in HANA?

Hello, all

How does one assign the result of a query to a scalar variable in HANA? In MS SQL I could:

SET @myvar = ( SELECT CardName FROM OCRD WHERE CardCode = @cc )

or, for several variables:

SELECT @var1 = Field1, @var2 = Field2 FROM MYTABLE WHERE Code = @code

The only way to do itin HANA that I have found is via a very long compass, i.e. by dint of a cursor. But cursors being intended for the iteration over several data rows, they are very clumsy in such simple an operation as a single assignment of a single scalar variable. I should say it is actually an abuse of cursor, so there ought to be a better way. Is there one?

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Jul 02 at 12:23 PM
    -2

    Here is an example, ready for testing in Hana Studio:

    DO
    BEGIN
        DECLARE V1, v2 vARCHAR(8);
        SELECT 'Hello', 'there' INTO V1, V2 FROM DUMMY;
        SELECT :V1, :V2 FROM DUMMY;
    END;
    Add comment
    10|10000 characters needed characters exceeded