Answers for "SAP HANA Exclude weekends while calculating diff between two dates."
https://answers.sap.com/questions/579246/sap-hana-exclude-weekends-while-calculating-diff-b-1.html
The latest answers for the question "SAP HANA Exclude weekends while calculating diff between two dates."Answer by Kuldeep Jain
https://answers.sap.com/answers/579452/view.html
<p>Hi Ramana,</p>
<p></p>
<p>I have taken your scenario as a challenge for me and tried some SQL coding. It's not perfect even bad way. I am trying my hands with SQL codes.</p>
<p>It might give you some idea.</p>
<pre>DO
BEGIN
declare v_i integer;
declare v_count integer;
sel1 = select
"0CALDAY" as "CALDAY",
"Yesterday" as "YESTERSDAY",
sum("DATE_DIFF") AS "DATE_DIFF" ,
sum((select 0 from dummy)) as "HOUR_DIFF",
sum((select 0 from dummy)) as "WRK_HOUR_DIFF"
from "_SYS_BIC"."ZTABLE"
-- where "0CALDAY" >= '20180701'
GROUP BY "0CALDAY", "Yesterday";
select count(*) into v_count from :sel1;
for v_i in 1..v_count do
WHILE to_date(:sel1.CALDAY[v_i]) < to_date(:sel1.YESTERSDAY[v_i]) do
if( weekday(to_date(:sel1.CALDAY[v_i])) ) < 5
then
sel1.WRK_HOUR_DIFF[v_i] = :sel1.WRK_HOUR_DIFF[v_i] + 24 ;
sel1.HOUR_DIFF[v_i] = :sel1.HOUR_DIFF[v_i] + 24 ;
else
sel1.HOUR_DIFF[v_i] = :sel1.HOUR_DIFF[v_i] + 24 ;
end if;
sel1.CALDAY[v_i] = ADD_DAYS(to_date(:sel1.CALDAY[v_i]), 1) ;
end while ;
end for;
select * from :sel1;
END;
</pre>Fri, 27 Jul 2018 17:32:20 GMTKuldeep Jain