Třídová akce

Kód:
21
Tělo:
#ORA
Select
  *
From
  (
#ALL
Select
#IB
  First :MaxRowsCount
#MS
  TOP (:MaxRowsCount)
#ALL
  /* Stejné StoreCard_ID, QUnit, UnitRate a StoreBatch_ID */
  Case (
    Select
      count(*)
    From
      LogStoreContentsForStrat_VIEW IC
    Where
      IC.Parent_ID = S.Position_ID and
      IC.StoreCard_ID = :StoreCard_ID and
      (
        (
          IC.StoreBatch_ID is null and
          :SBatch_ID_NULL = 'A'
        ) or
        (IC.StoreBatch_ID =  :StoreBatch_ID)
      ) and
      IC.QUnit = :QUnit and
      (
        ((IC.UnitRate - :UnitRate) < 0.0005) and
        ((:UnitRate - IC.UnitRate) < 0.0005)
      )
  ) when 0 then 100 else 0 end
  +
  /* Stejné StoreCard_ID v pozici, ale jiný QUnit, UnitRate nebo StoreBatch_ID */
  Case (
    Select
      count(*)
    From
      LogStoreContentsForStrat_VIEW IC
    Where
      IC.Parent_ID = S.Position_ID and
      IC.StoreCard_ID = :StoreCard_ID and
      (
        (
          (IC.StoreBatch_ID <> :StoreBatch_ID) and
          (IC.StoreBatch_ID is not null) and
          (:SBatch_ID_NULL = 'N')
        ) or
        (
          IC.StoreBatch_ID is null and
          :SBatch_ID_NULL = 'N'
        ) or
        (
          IC.StoreBatch_ID is not null and
          :SBatch_ID_NULL = 'A'        
        ) or
        (IC.QUnit <> :QUnit) or
        ((IC.UnitRate - :UnitRate) > 0.0005) or
        ((:UnitRate - IC.UnitRate) > 0.0005)
      )
  ) when 0 then 0 else 10 end
  +
  /* Jiné StoreCard_ID ve stejné pozici */
  Case (
    Select
      count(*)
    From
      LogStoreContentsForStrat_VIEW IC
    Where
      IC.Parent_ID = S.Position_ID and
      IC.StoreCard_ID <> :StoreCard_ID
  ) when 0 then 0 else 1000 end Score,
  ID,
  Position_ID,
  Position_Code,
  Position_Accessibility,
  Position_Frozen,
  Quantity,  
  QUnit,
  UnitRate,
  IndivisibleQuantity,  
  CompareStorageDate$DATE,
  StoreBatch_Name,
  PositionType
from
#ORA
  Table
    (
    Cast
      (      
      LogstoreCustOutputStrat(
        :StoreCard_ID,
        :Store_ID,
        :StoreBatch_ID,
        :SBATCH_ID_NULL,
        :Quantity,
        :AccessibilityLimit,
        :IsAccessibilityLimitFilter,
        'A',
        :RespectIndivisibleQuantity)        
        as LogStoreCustOutputStrat_Table  
      )
    ) S
#IB
      LogstoreCustOutputStrat(
        :StoreCard_ID,
        :Store_ID,
        :StoreBatch_ID,
        :SBATCH_ID_NULL,
        :Quantity,
        :AccessibilityLimit,
        :IsAccessibilityLimitFilter,
        'A',
        :RespectIndivisibleQuantity) S
#MS
      LogstoreCustOutputStrat(
        :StoreCard_ID,
        :Store_ID,
        :StoreBatch_ID,
        :SBATCH_ID_NULL,
        :Quantity,
        :AccessibilityLimit,
        :IsAccessibilityLimitFilter,
        'A',
        :RespectIndivisibleQuantity) S                
#ALL
order by
  Position_Frozen Desc, 1,  (Case when (QUnit = :QUnit) and (UnitRate = :UnitRate) then 0 else 1 end), 7, Position_Accessibility
#ORA
  )
where
  RowNum <= :MaxRowsCount

Generated by ABRA Software a.s. 27.10.2021 16:35:19