I write a code which gives me wrong answer what it do it compare dates from two tables and checks Sunday from it and return me sum of item column it checks Sunday its work fine but when it checks other table date and compare with its own dates and then give sum is wrong please help on this thanks
You can also checks on dbfiddle here.
DECLARE
a number;
B DATE;
CURSOR GZDT IS
SELECT GAZZETED_DATE FROM GAZZETED_DAYS
WHERE GAZZETED_DATE between date '2021-01-01' and date '2021-01-20';
begin
OPEN GZDT;
LOOP
FETCH GZDT INTO B;
EXIT WHEN GZDT%notfound;
END LOOP;
CLOSE GZDT;
SELECT SUM(ITEM) into a from pay_in_out
where TO_CHAR(att_date,'DY', 'NLS_DATE_LANGUAGE=AMERICAN') NOT IN ('SUN')
AND ATT_DATE != B
AND att_date between date '2021-01-01' and date '2021-01-20'
AND EMP_CODE = 100;
dbms_output.put_line('the sum of item is :'||a) ;
end;
/