USE [VEPROMS]
DECLARE @RowsAffected int
DECLARE @InternalTransitions TABLE
	(
		TransitionID int,
		FromID int,			-- contentid
		TranType int,
		ToID int,
		RangeID int,
		OldTransitionID int
	)
	Insert into @InternalTransitions select * from vefn_FindInternalTransitionsForCopy(10356)
SELECT * From Children
SELECT * From @InternalTransitions
SELECT C1.Text, IT.OldTransitionID,IT.TranType,IT.ToID,IT.RangeID, IT.[TransitionID], NNT.ItemID, NNR.ItemID
				FROM CONTENTS C1
				JOIN @InternalTransitions IT ON C1.ContentID = IT.FromID
				LEFT JOIN Children NNT on IT.ToID = NNT.NewItemID
				LEFT JOIN Children NNR on IT.RangeID = NNR.NewItemID --C2 ON CC.ContentID = C2.ContentID
	IF (SELECT COUNT(*) from @InternalTransitions) > 0   -- found transitions internal to copied step
	BEGIN
		SET @RowsAffected=1
		WHILE @RowsAffected > 0
		BEGIN
			-- Need to update the 'to' and 'range' transition fields within the content records
			Update CC SET [TEXT] = C2.NewText
				FROM CONTENTS CC
				JOIN (SELECT C1.ContentID, .dbo.vefn_FixTransitionTextForCopy([Text], IT.OldTransitionID,IT.TranType,NNT.ItemID,NNR.ItemID,IT.[TransitionID], IT.ToID,IT.RangeID) NewText
				FROM CONTENTS C1
				JOIN @InternalTransitions IT ON C1.ContentID = IT.FromID
				LEFT JOIN Children NNT on IT.ToID = NNT.NewItemID
				LEFT JOIN Children NNR on IT.RangeID = NNR.NewItemID) C2 ON CC.ContentID = C2.ContentID
				WHERE [TEXT] <> C2.NewText
			SET @RowsAffected = @@RowCount
		END
	END
/*
		UPDATE CC SET [TEXT] = C2.NewText
			FROM CONTENTS CC
			JOIN (SELECT C1.ContentID, .dbo.vefn_FixTransitionTextCopy(C1.Text, CAST(TR.[Config] as int), TR.TranType,  TR.[ToID], TR.[RangeID],TR.[TransitionID]) NewText
			FROM CONTENTS C1
			JOIN @Children NN on C1.ContentID = NN.NewContentID
			JOIN Transitions TR on NN.NewContentID = TR.FromID) C2 ON CC.ContentID = C2.ContentID
			WHERE [TEXT] <> C2.NewText
			SET @RowsAffected = @@RowCount
END
*/