SELECT XX.*, SC.Code, SC.Name FROM (SELECT SA2.StoreCard_ID as StoreCard_ID, SA2.QUnit, max(SA.StartDate$DATE) as LastDocDate$Date, sum(SA2.Quantity) as TotalQuantity, count(SA.ID) as UsedCount FROM ServiceAssemblyForms2 SA2, ServiceAssemblyForms SA, ServiceDocuments SD WHERE SA2.Parent_ID=SA.id and SA.ServiceDocument_ID=SD.ID and SD.ServicedObjectType_ID = :OBJID and SA2.ItemType=1 GROUP BY SA2.StoreCard_ID, SA2.QUnit) XX, StoreCards SC WHERE XX.StoreCard_ID = SC.ID ORDER BY XX.LastDocDate$Date desc
Generated by ABRA Software a.s. 27.10.2021 16:35:46