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

Re: DECLARE not working in SQL Console

$
0
0

hi Ben,

 

regarding using DECLARE directly in a HANA SQL console, i believe that DECLARE is available as part of sql script and cannot be used outside of a procedure....according to here anyway.

 

as for the dummy table, it's useful for retrieving function results without the need for a schema.table being used...

 

e.g. SELECT NOW() FROM DUMMY to get the current datetime.

 

as to why you can't just use SELECT NOW() directly, that i am not sure of...hopefully someone else on the forum has an answer to that.

 

out of curiosity, are you trying to retrieve the row number as a function of your result set?

 

if so, you can use the ROW_NUMBER() window function by defining it like below...

 

select
SUPPLIERID,
count(distinct PRODUCTID),
quarter(DATEORDERED),
ROW_NUMBER() OVER (ORDER BY SUPPLIERID, QUARTER(DATEORDERED)) AS ROW_NUM
 
from "STS"."FCTSUPPLIERORDERS"
where year (DATEORDERED) = (select max(year(DATEORDERED)) from "STS"."FCTSUPPLIERORDERS")

group by SUPPLIERID, quarter(DATEORDERED)
order by SUPPLIERID, quarter(DATEORDERED)

 

 

there is also the option to partition the row number window function should you wish to reset the count on a particular change of field. you can see more about this and other window functions here.

 

cheers,

jamie

 

 

 

 


Viewing all articles
Browse latest Browse all 9165

Trending Articles



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