title: SQL Server 2008 - How do i return a User-Defined Table Type from a Table-Valued Function?
body: <p>Here's my user-defined table type...</p>
  
  <pre><code>CREATE TYPE [dbo].[FooType] AS TABLE(
   [Bar] [INT],
  )
  </code></pre>
  
  <p>This is what ive had to do in my table-valued function to return the type:</p>
  
  <pre><code>CREATE FUNCTION [dbo].[GetFoos]
  RETURN @FooTypes TABLE ([Bar] [INT])
  INSERT INTO @FooTypes (1)
  RETURN
  </code></pre>
  
  <p>Basically, im having to re-declare my type definition in the RETURN statement of the function. Isnt there a way i can simply declare the type in the RETURN statement?</p>
  
  <p>I would have thought this would work:</p>
  
  <pre><code>CREATE FUNCTION [dbo].[GetFoos]
  RETURN @FooTypes [FooType]
  INSERT INTO @FooTypes (1)
  RETURN
  </code></pre>
  
  <p>Cannot find any help on MSDN/Google regarding this....anyone?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I unmarked my answer, and bumping this question - as i am encountering the same scenario 6 months later.</p>
  
  <p>Does anyone have any idea if it's possible to return a user defined table type from a table valued function? If not, is there a better workaround other than what i have done? (re-declare the type again).</p>