select count(A.ID)
from Accounts A
where (A.TypeOfActivity = 1) and
(
((select count(GL.ID)
from GeneralLedger GL
where ((GL.AccDate$DATE >= :DateFrom) and
(GL.AccDate$DATE <= :DateTo)) and
((GL.DebitAccount_ID = A.ID) or
(GL.CreditAccount_ID = A.ID))) > 0) or
((select count(AB.ID)
from AccountBeginnings AB
left join Periods PE on PE.ID = AB.Period_ID
where (AB.Account_ID = A.ID) and
(PE.DateFrom$DATE = :DateFrom) and
((AB.DebitAmount <> 0) or (AB.CreditAmount <> 0))) > 0)
) Generated by ABRA Software a.s. 27.10.2021 16:34:09