title: tsql returning a table from a function or store procedure
body: <p>This is more of a syntax question
  I'm trying to write a store procedure or function that I can embed into a query such as:</p>
  
  <pre><code>select * from MyBigProcOrFunction
  </code></pre>
  
  <p>I'm trying to define a tabular function but I do not understand how to do it as I build tmp tables to work out the data before I finally have the return at the endtable. My mark up for my code is:</p>
  
  <pre><code>create function FnGetCompanyIdWithCategories()
  returns table
  as 
  return 
  (
  select * into a #tempTable from stuff
  '
  etc
  '
  select companyid,Company_MarketSector from #tempTables 'the returning table data
  )
  </code></pre>
  
  <p>If I define a function, How do I return it as a table?</p>