To be able to create an index view, the view must be deterministic, that is it must be the guarantied to be the same on every query of it.
Is your userfunction deterministic?
User-Defined Function Determinism
Whether a user-defined function is
deterministic or nondeterministic
depends on how the function is coded.
User-defined functions are
deterministic if:
* The function is schema-bound.
* All built-in or user-defined functions called by the user-defined
function are deterministic.
* The body of the function references no database objects outside
the scope of the function. For
example, a deterministic function
cannot reference tables other than
table variables that are local to the
function.
* The function does not call any extended stored procedures.
User-defined functions that do not
meet these criteria are marked as
nondeterministic. Built-in
nondeterministic functions are not
allowed in the body of user-defined
functions.
Is your function SchemaBound?
alter function [dbo].[UserFunction]
(@example int = 1 )
returns int
with schemabinding
as
begin
return 1
end
Is your view SchemaBound?
ALTER VIEW dbo.UserView
WITH SCHEMABINDING
AS
SELECT ID, [dbo].userFunction
To create an indexed view you must first create a unique clustered index(See FAQ a bottom).