use envisage

IF exists (select 1 from sys.columns where name like 'UseProbability' and object_id = OBJECT_ID('Scenario'))
BEGIN
	ALTER TABLE Project
		ADD [Probability] decimal (5,4) not null constraint df_Probability1 default 1
	
	ALTER TABLE Project drop constraint df_Probability1

END
GO
IF exists (select 1 from sys.columns where name like 'ExpectedProbability' and object_id = OBJECT_ID('Scenario'))
BEGIN
	UPDATE [Project] SET [Probability] = ISNULL ((select top 1 [ExpectedProbability] from Scenario where Scenario.ParentId = Project.Id order by [Status] desc), 1)
	
	ALTER TABLE Scenario
		DROP COLUMN [highProbability], [ExpectedProbability], [LowProbability], [UseProbability]

	ALTER TABLE ScenarioCln
		DROP COLUMN [highProbability], [ExpectedProbability], [LowProbability], [UseProbability]
END



--select * from sys.all_sql_modules where definition like '%priority%' and definition like '%scenario%'