#ORA
Select
*
From
(
Select
#MS
Select
TOP (:MaxRowsCount)
#IB
Select
First :MaxRowsCount
#ALL
SP.Accessibility Score,
SP.ID,
SP.Code,
SP.Accessibility,
SP.BasicFreeSpace,
SP.BasicFreeWeight,
/* Zda je pozice preferovaná */
Case (
Select
Count(P2.ID)
From
LogStorePreferences2 P2
Left Join Firms F on P2.Firm_ID = F.ID
Where
(
(P2.Parent_ID = PP.ID) or
(P2.Parent_ID = PC.ID)
) and
(P2.Strictly = 0) and
(
P2.StoreCard_ID = :StoreCard_ID or
P2.StoreCardCategory_ID = :StoreCardCategory_ID or
P2.StoreMenuItem_ID = :StoreMenuItem_ID or
P2.Firm_ID = :Firm_ID or
F.Firm_ID = :Firm_ID
)
) when 0 then 0 else 1 end Preferred
From
LogStorePositionsForStrat_VIEW SP
LEFT JOIN LogStorePreferences PP ON SP.ID = PP.StorePosition_id
LEFT JOIN LogStorePreferences PC ON SP.Code like PC.StorePositionAddress || '%'
Where
((SP.PositionType = 0) OR (:IsReservedForDoc = 'A')) and
SP.Hidden = 'N' and
SP.Frozen = 'N' and
((SP.Accessibility < :AccessibilityLimit) or (:IsAccessibilityLimitFilter = 'N')) and
SP.Store_ID = :Store_ID and
SP.BasicFreeWeight >= :UnitBasicWeight and
SP.BasicFreeSpace >= :UnitBasicCapacity and
(
(Case When (Case When SP.Width > SP.Height then SP.Width Else SP.Height end) > SP.Depth then (Case When SP.Width > SP.Height then SP.Width Else SP.Height end) else SP.Depth end) *
Cast((Case SP.SizeUnit When 0 then 100 When 1 then 10 When 2 then 1 else 1 end) as Float)
) >= :UnitBasicMaxSize and
(
(:IsReservedForDoc = 'A' and SP.ReservedForDoc_ID = :ReservedForDocID and SP.ReservedForDocType = :ReservedForDocType) or
(:IsReservedForDoc = 'N' and SP.ReservedForDoc_ID is null)
)
{PREFSTRICTLY}
Order by
SP.Accessibility, 7 desc
#ORA
)
where
RowNum <= :MaxRowsCountGenerated by ABRA Software a.s. 27.10.2021 16:35:19