Operation Details
Description:  
Sterotype: nsmulti
SQL
SELECT
  determinationPackageVersionID,
  determinationConfigID,
  minAge,
  maxAge,
  gender,
  productID,
  determinationPackageID,
  flag,
  toDate
INTO
  :determinationPackageVersionID,
  :determinationConfigID,
  :minAge,
  :maxAge,
  :gender,
  :productID,
  :determinationPackageID,
  :flag,
  :todate 
FROM
  DeterminationPackageVersion 
WHERE determinationConfigID = :determinationConfigID 
  AND 
  (
    
    (
      :genderNullInd = '1' 
      AND gender IS NULL 
    ) 
    OR gender = :gender 
  ) 
  AND 
  (
    
    (
      :productNullInd = '1' 
      AND productID IS NULL 
    ) 
    OR productID = :productID 
  ) 
  AND 
  (
    
    (
      :flag = 4 
      AND 
      (
        
        (
          :minAge BETWEEN minAge AND maxAge 
        ) 
        OR 
        (
          :maxAge BETWEEN minAge AND maxAge 
        ) 
        OR 
        (
          minAge IS NULL 
          AND maxAge >= :minAge 
        ) 
        OR 
        (
          maxAge IS NULL 
          AND minAge <= :maxAge 
        ) 
      ) 
    ) 
    OR 
    (
      :flag = 1 
      AND 
      (
        flag = 1 
        OR 
        (
          :minAge <= maxAge 
        ) 
      ) 
    ) 
    OR 
    (
      :flag = 2 
      AND 
      (
        flag = 2 
        OR 
        (
          :maxAge >= minAge 
        ) 
      ) 
    ) 
    OR 
    (
      :flag = 3 
      AND flag = 3 
    ) 
  ) 
  AND determinationPackageVersionID IN 
  ( 
  SELECT
    determinationPackageVersionID 
  FROM
    DeterminationPackageVersion 
  WHERE determinationPackageID <> :determinationPackageID 
    AND versionStatus = 'DPST1' 
  
  UNION
    
  SELECT
    determinationPackageVersionID 
  FROM
    DeterminationPackageVersion dpv1 
  WHERE determinationPkgVersionNumber = 
    ( 
    SELECT
      MAX(determinationPkgVersionNumber ) 
    FROM
      DeterminationPackageVersion dpv2 
    WHERE dpv1.determinationPackageID = dpv2.determinationPackageID 
      AND dpv2.determinationPackageID <> :determinationPackageID 
      AND dpv2.versionStatus = :versionStatus 
    ) 
  )