 STATUS = statusFor ( select active from rf2_concept_sv c
 						where ch.componentid = c.id
 						and ch.releaseversion = c.effectiveTime ),
-Reason =  @S_CHANGE
+Reason =  @CS_CHANGE
 WHERE EXISTS (
 	SELECT 1 FROM rf2_concept_sv c2, rf2_concept_sv c3
 	WHERE ch.componentid = c2.id

	and NOT t2.casesignificanceid = t.caseSignificanceId
);

SELECT * from rf21_COMPONENTHISTORY where componentid = 832350016;


-- Where there was a status change and the previous version had a different

WHERE c.effectiveTime >= @HISTORY_START;

-- Where the concept entry in the history has no previous entry in the history, 
-- then we'll mark the status as 0 - Created.   
-- Watch out for components that are created in an inactive state however.
UPDATE rf21_COMPONENTHISTORY ch 
SET CHANGETYPE=0,
STATUS = ( select statusFor(c.active) from rf2_concept_sv c
			where c.id = ch.componentid
			and c.effectiveTime = ch.releaseversion )
WHERE isConcept = true
AND NOT EXISTS (
	SELECT 1 from rf2_concept_sv cf
