

DROP VIEW [dbo].[View_Project_MasterDataAnalysis]
GO


CREATE VIEW [dbo].[View_Project_MasterDataAnalysis] AS 
WITH LastData AS (
    SELECT ReportDate, MAX(DataDate) AS LatestDate
    FROM dbo.Project_MasterDataAnalysis AS tba
    GROUP BY tba.ReportDate
),RankedData AS (
	SELECT tbb.*
    FROM dbo.Project_MasterDataAnalysis tbb
		INNER JOIN LastData AS ld ON  tbb.DataDate = ld.LatestDate
)
SELECT
    rd.*
FROM RankedData AS rd

GO

