select
SDocs.ID, SDocs.DocumentType
from
DocRowBatches DRB
join StoreDocuments2 SDocs2 on DRB.Parent_ID = SDocs2.ID
join StoreDocuments SDocs on SDocs2.Parent_ID = SDocs.ID
join SPMAssemblyLists SMPAL on (SDocs.ID = SMPAL.MaterialDistribution_ID) or (SDocs.ID = SMPAL.ProductReception_ID)
where
DRB.StoreBatch_ID = :StoreBatch_ID and
SDocs.DocumentType in ('27', '28') Generated by ABRA Software a.s. 27.10.2021 16:34:11