我意識到這是一個很做作的例子,但我已經簡化了完整版到這表明了問題的情況如下:的SQL Server索引視圖錯誤
CREATE VIEW model.Appointments_Partition1
WITH SCHEMABINDING AS
SELECT CONVERT(varchar(15), AppointmentId) as Id,
ap.AppTypeId as AppointmentTypeId,
ap.Duration as DurationMinutes,
ap.AppointmentId as EncounterId,
COUNT_BIG(*) as __count_big
FROM dbo.Appointments ap
JOIN dbo.PracticeCodeTable pct ON SUBSTRING(pct.Code, 1, 1) = ap.ScheduleStatus
AND pct.ReferenceType = 'AppointmentStatus'
WHERE ap.AppTime > 0
GROUP BY CONVERT(varchar(15), AppointmentId), ap.AppTypeId, ap.Duration, ap.AppointmentId
CREATE UNIQUE CLUSTERED INDEX [IX_Appointments_Partition1_Id]
ON model.Appointments_Partition1 ([Id]);
我得到:
因爲該視圖的選擇列表包含聚合函數或分組列的結果的表達式消息8668,級別16,狀態0,第12行
無法對視圖創建聚集索引「IX_Appointments_Partition1_Id「PracticeRepository.model.Appointments_Partition1」。考慮從選擇列表中刪除聚合函數或分組列的結果上的表達式。
我包括count_big ...那麼爲什麼組是由一個問題?....我怎樣才能解決這個錯誤?
不知道我理解? – Jeff