I'm trying to create indexed view containing only the data for the last 2 weeks.
This part works fine:
CREATE VIEW [dbo].[MainLogView]
WITH SCHEMABINDING
AS
SELECT Id, Date, System, [Function], StartTime, EndTime, Duration, ResponseIsSuccess, ResponseErrors
FROM dbo.MainLog
WHERE (Date >= DATEADD(day, - 14, GETDATE()))
But when I try add index:
CREATE UNIQUE CLUSTERED INDEX IDX_V1
ON MainLogView (Id);
I'm geting:
Cannot create index on view 'dbo.MainLogView'. The function 'getdate' yields nondeterministic results. Use a deterministic system function, or modify the user-defined function to return deterministic results.
I know why, but how to reduce the data in a view for the last 2 weeks? I need small and fast querable portion of data from my table.