title: SQL Server: From a view, calling a function with a table-valued parameter
body: <p>In SQL Server, if I have a scalar-value function that takes a table-valued parameter argument, defined as follows (simplified example):</p>
  
  <pre><code>CREATE TYPE IntTableType AS TABLE(Value INT); 
  
  CREATE FUNCTION dbo.MeetsCustomRequirements
  (
      @TypeIDs IntTableType READONLY
  )
  RETURNS TINYINT AS 
  BEGIN
      -- (Function logic here; returns either 0 or 1 based on the specified @TypeIDs values)
  END
  </code></pre>
  
  <p>I'd like to be able to call that function from a view, where the table-valued parameter of the view is generated from an inline query, like:</p>
  
  <pre><code>CREATE VIEW dbo.vEligibleItems AS 
      SELECT i.ItemID
      FROM tItems i
      WHERE dbo.MeetsCustomRequirements (
          (SELECT TypeID FROM tItemTypes WHERE ItemID = i.ItemID)
      );
  </code></pre>
  
  <p>However, this doesn't work because the result of that nested SELECT query isn't an <code>IntTableType</code> (even though it <em>is</em> a list of <code>INT</code> values).  (Specific error generated is <code>Error 206: Operand type clash: int is incompatible with IntTableType</code>.)</p>
  
  <p>My two-part question: Is there a way to call a function taking a table-valued parameter argument from a view?  If not, what alternative approaches are available to accomplish the same thing?</p>
  
  <p>Database is SQL Server 2008.</p>
  
  <p>(Bringing the logic in the function inline in the view is not ideal because the function is called from several different places, not just from this one view.)</p>