I have tried using derived tables to generate a unique value for Schema-bounded Unique Index but Derived Tables are not acceptable for Schema-bounded Unique Indexes. I've tried to use NEWID() and generated a unique ID for every field, but it doesn't work either telling that only deterministic values are allowed.
There's no other unique key in most of my views. Now what to do please?
Pasting code below, if it helps
.
Regards,
K
IF OBJECT_ID('vuDailySE_Progress_GroupBy', 'V') IS NOT NULL
DROP VIEW vuDailySE_Progress_GroupBy
GO
CREATE VIEW vuDailySE_Progress_GroupBy
WITH SCHEMABINDING
AS
SELECT
ROW_NUMBER() OVER (ORDER BY DateAdded) AS ID, DateAdded, Region, Location, Project, PM, SupervisorID, AreaID, WorkPackID, [Earned HoursSum], [Earned ValueSum]
FROM (
SELECT
--NEWID() AS ViewID,
CONVERT(Date, tblProgress_Daily.Date_Added) AS DateAdded,
tblWBS_Lev0_Project.Region,
tblWBS_Lev0_Project.Location,
tblWBS_Lev0_Project.ID AS Project,
tblEmployee.FullName AS PM,
tblProgress_Daily.SupervisorID,
tblWBS_Lev2_Area.ID AS AreaID,
tblWBS_Lev3_WorkPack.ID AS WorkPackID,
Sum(tblProgress_Daily.Today_ManHour) AS [Earned HoursSum],
Sum(tblProgress_Daily.Today_Earned_Value) AS [Earned ValueSum],
COUNT_BIG(*) AS RecCount
FROM
dbo.tblWBS_Lev0_Project
INNER JOIN
dbo.tblROC_InstallationType ON tblWBS_Lev0_Project.ID = tblROC_InstallationType.ProjectID
INNER JOIN
dbo.tblWBS_Lev3_WorkPack ON tblROC_InstallationType.WorkPackID = tblWBS_Lev3_WorkPack.ID
INNER JOIN
dbo.tblWBS_Lev2_Area ON tblROC_InstallationType.AreaID = tblWBS_Lev2_Area.ID
INNER JOIN
dbo.tblBoQ ON tblROC_InstallationType.ID = tblBoQ.InstallationTypeID
INNER JOIN
dbo.tblBoQ_Progress ON tblBoQ.ID = tblBoQ_Progress.BoQID
INNER JOIN
dbo.tblProgress_Daily ON tblBoQ_Progress.ID = tblProgress_Daily.BoQProgressID
INNER JOIN
dbo.tblProject_Supervisor ON tblProgress_Daily.SupervisorID = tblProject_Supervisor.ID
INNER JOIN
dbo.tblProjectManager ON tblProject_Supervisor.ProjectManagerID = tblProjectManager.ID
INNER JOIN
dbo.tblEmployee ON tblProjectManager.ProjectManager = tblEmployee.ID
GROUP BY
CONVERT(Date, [tblProgress_Daily].[Date_Added]),
tblWBS_Lev0_Project.Region,
tblWBS_Lev0_Project.Location,
tblWBS_Lev0_Project.ID,
tblEmployee.FullName,
tblProgress_Daily.SupervisorID,
tblWBS_Lev2_Area.ID,
tblWBS_Lev3_WorkPack.ID
) AS MyResults
GO
CREATE UNIQUE CLUSTERED INDEX IX_U_SEProgressGroupby ON vuDailySE_Progress_GroupBy(ViewID)
GO