Svidos29
2nd June 2018, 11:43
Hello,

i've a little problem that i don't know how to manage.

The problem is: I'm selecting a table in order DESC, with some conditions, i've to check if the record that i have selected has 0 sum (of a field in another table that i'm selecting in the selectdo). Here, there are some possibilities:
1) if there is another record after this, it means that it can take the values of this (previous) record;
2) if there are no previous records, it has to take the values for the unique current record that is selected;
3) if the sum is not 0, it has to take the values of the current record;

I hope i explained myself

If i can help i would attach the current code that i built, that doesn't work for the condition number 2.

Thanks, in advance

giggty
4th June 2018, 14:27
Please post your code to make your problem (hopefully) less vague :)

Svidos29
4th June 2018, 19:17
hi,

here the code:

select tctax100.*
from tctax100
where tctax100.otof = :cisli220.pfbp
order by tctax100._index4 desc
selectdo
select tctax910.nreg, tctax910.bpid
from tctax910
selectdo
select sum(tctax910.amnt):tmp.amnt
from tctax910
where tctax910.nreg = :tctax100.nreg.c
and tctax910.bpid = :tctax100.otof
selectdo
return
selectempty
break
endselect

giggty
6th June 2018, 11:03
Sorry, but It is still not clear to me :)
Let me recap:
1. You want to get a rowset of tctax100. (What for? Are you building a report?)
2. For the first row you want to get this first row.
3. For rows from number 2 to the last one you want the previous one instead (i. e. instead of 2nd you want 1st and for the last one you want the penultimate - so you have 2 identical first rows?)
4. 3 stays valid unless select sum(tctax910.amnt) for the current row is not 0 - then you want the current row.
Is that 100% correct?