select
p.LastName as LastName,
sc2.inventorynr as outInventoryNr,
sc2.responsible_id as outResponsible_id,
sc2.quantity as outQuantity
{ANDFIELDS}
from
SmallAssetCards2 SC2
LEFT JOIN AssetResponsibles AR on SC2.responsible_id = AR.ID
LEFT JOIN Persons P ON AR.Person_ID = P.ID
JOIN SmallAssetCards SC ON SC2.Parent_ID = SC.ID
{WHERE}
union all
select
p.LastName as LastName,
sc.inventorynr as outInventoryNr,
sc.responsible_id as outResponsible_id,
sc.quantity as outQuantity
{ANDFIELDS}
from
SmallAssetCards SC
LEFT JOIN AssetResponsibles AR on SC.responsible_id = AR.ID
LEFT JOIN Persons P ON AR.Person_ID = P.ID
where
not exists (select sc_2.id from SmallAssetCards2 SC_2 where SC.ID = SC_2.Parent_ID)
{ANDWHERE}
order by %LastName%