on 11-02-2016 11:24 AM
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?
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;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here is the link to SAP Help Doc for quick reference. I stumbled upon this post and then looked for the same in docs.
In B1, the code does not need the surrounding procedural block:
DECLARE V1, v2 vARCHAR(8);
SELECT 'Hello', 'there' INTO V1, V2 FROM DUMMY;
SELECT :V1, :V2 FROM DUMMY;
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.