title: Cannot create index on view with User Defined Function in SQL Server
body: <p>In SQL Server 2005, I'm trying to use a User Defined Function in a indexed view that will be used in a full-text index. I have been able to get the UDF to work with a stored procedure and the view in question. But, when I try to create an index on the view I get the following error...</p>
  
  <p><strong>Cannot create index on view "DevDatabase.dbo.View_PersonSearch" because function "dbo.GetCurrentImage" referenced by the view performs user or system data access.</strong></p>
  
  <p>I am stumped by this. Below is an example of what I am trying to do. Am I missing something or is this even possible?</p>
  
  <p><em>User Defined Function</em></p>
  
  <pre><code>SET ANSI_NULLS ON
  GO
  SET QUOTED_IDENTIFIER ON
  GO
  
  ALTER FUNCTION [dbo].[GetCurrentImage](@Person_ID int) 
  RETURNS int
  WITH SCHEMABINDING
  AS
  BEGIN
  
      -- Declare the return variable here
      DECLARE @Img_ID int
  
      SET @Img_ID = (**sql that selects image** )
  
      RETURN @Img_ID
  
  END
  GO
  </code></pre>
  
  <p><em>View with index creation</em></p>
  
  <pre><code>SET ANSI_NULLS ON
  GO
  SET QUOTED_IDENTIFIER ON
  GO
  
  ALTER VIEW [dbo].[View_PersonSearch]
  WITH SCHEMABINDING
  AS
      SELECT  Person_ID,
              (**Select fields to search on**) AS SearchArea,
              dbo.GetCurrentImage(Person_ID) AS FK_Img_ID
  FROM    dbo.Person
  GO
  
  CREATE UNIQUE CLUSTERED INDEX Index_Person_ID ON [View_PersonSearch](Person_ID)
  GO
  </code></pre>