title: Table variable in User Defined Function SQL Server and performance of UDF
body: <p>I have an UDF like this</p>
  
  <pre><code>CREATE FUNCTION Lob_function
  (
      @policy NVARCHAR(MAX)
      @table  Table
  )
  RETURNS NVARCHAR(MAX)
  AS 
  BEGIN
  select @policy= 
  case
  when @policy like '%AMM%' then 'AMM'
  when @policy like '%MOT%' then 'MOT'
  when @policy like '%MOX%' then 'MOX'
  when @policy not like '00%' then LEFT(@policy,3)
  end
  from @table
  return @policy
  END;
  </code></pre>
  
  <p>I want to use my UDF for various cases like : </p>
  
  <pre><code>Select Lob_function (@policy, @table) from @table.
  </code></pre>
  
  <p>It appears an error on @table  Table, when I replace @table by a fixed table, my UDF can be executed but very slowly compared with a normal Select statement.</p>