select distinct X.ID, X.AssetType from (
select distinct
case
when :ARKind = 0 then A.AssetLocation_ID
when :ARKind = 1 then A.Responsible_ID
when :ARKind = 2 then A.EvidenceDivision_ID
when :ARKind = 3 then A.ExpensesDivision_ID
end as ID,
1 as AssetType
from
AssetCards A
where
(A.Status = 1) and
(A.PurchaseDate$Date <= :AInvDate) and
(A.FileInDate$Date <= :AInvDate)
union all
select distinct
case
when :ARKind = 0 then A.AssetLocation_ID
when :ARKind = 1 then A.Responsible_ID
when :ARKind = 2 then A.EvidenceDivision_ID
when :ARKind = 3 then A.ExpensesDivision_ID
end as ID,
2 as AssetType
from
SmallAssetCards A
where
(A.Status = 0) and
(A.PurchaseDate$Date <= :AInvDate)
union all
select distinct
case
when :ARKind = 1 then A.Responsible_ID
end as ID,
2 as AssetType
from
SmallAssetCards2 A
join SmallAssetCards AC on AC.id = A.Parent_ID
where
(:ARKind = 1) and (AC.status = 0) and (AC.quantity > 1) and
(AC.PurchaseDate$Date <= :AInvDate)
) X
Generated by ABRA Software a.s. 27.10.2021 16:34:24