Quantcast
Channel: SCN: Message List - SAP HANA Developer Center
Viewing all articles
Browse latest Browse all 9165

Re: Error in SQL query

$
0
0

Two mistakes here:

1. Variables only get the colon (:) prefix when they are referenced, but not for declaration or assignment.


2. Result sets of queries are always assigned to table variables and not to literal variables.


 

   var1 = select sum(salary) from dummy;

   var2 = select count(salary) from dummy group by ID;

 

   var3 = :var1/:var2.  <<-- this doesn't work as var1 and var2 are table variables and not literals!

 

But i am facing syntax issues. can someone help?

 

   declare var_sum int;

 

    var_sum = select sum("SALARY") as "Sum_Salary",

             from "Sumeet"."EMPLOYEE"

           group by "REGION";


var_sum is declared as a integer literal but you try to assign a result set to it.

 

To get the  values assigned to your literal values you can use different tools:

1. Use SELECT ... INTO :variable_name ...  (as the other commentators already mentioned)

2. Use a cursor and loop over each record to access the literal values. Check the documentation for details.

3. Use a result set to ARRAY conversion to get the result set into an array of literal values. Again, the documentation is your friend here.

 

- Lars


Viewing all articles
Browse latest Browse all 9165

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>