Use [EnVisage]

IF EXISTS(SELECT * FROM sys.views WHERE Name = N'VW_ScenarioForecastTotalCost')
BEGIN
	DROP VIEW VW_ScenarioForecastTotalCost
	PRINT 'VW_ScenarioForecastTotalCost dropped'
END
GO

CREATE VIEW [dbo].[VW_ScenarioForecastTotalCost] AS
SELECT A.ParentID AS ForecastScenarioId, SUM(A.Cost) AS TotalCost, SUM(A.Quantity) TotalQuantity
FROM ScenarioDetail A
INNER JOIN VW_ScenarioRelations B ON (A.ParentID = B.ForecastScenarioId)
LEFT JOIN VW_ScenarioActualsPeriod C ON (B.ActualsScenarioId = C.ScenarioId) AND (A.WeekEndingDate <= C.EndDate)
GROUP BY A.ParentID