   AND ( 
      ch.changeType > ch2.changeType
      OR (ch.changeType = ch2.changeType AND ch.status = 1 AND NOT ch2.status = 1)
+     OR (ch.changeType = ch2.changeType AND ch.status = 0 AND NOT ch2.status = 0)
      )
 );

SET @CONCEPT_NON_CURRENT = 8;
SET @NOT_SET = -1;

-- PARALLEL_START;
-- Insert all concept changes into history and we'll work out what changes where made
-- in a subsequent pass.

CREATE INDEX idx_comphist_prev ON rf21_COMPONENTHISTORY(previousVersion);
CREATE INDEX idx_comphist_c ON rf21_COMPONENTHISTORY(isConcept);

SELECT * from rf21_COMPONENTHISTORY where componentid = @COMPONENT_OF_INTEREST;

-- Where there is no other change, but the inactivation indicator
-- is modified, add a new row.
