select
ID
from
Documents Doc
where
Doc.ProcessingType = 4
and Doc.Closed <> 'A'
AND Revided_ID IS NULL
and (:DocumentClassSelID = Cast(' ' as char(10)) or Doc.Category_ID in (select Obj_ID from Seldat where Sel_ID = :DocumentClassSelID))
order by
Doc.DocDate$DATE Generated by ABRA Software a.s. 27.10.2021 16:34:08