title: Table-Valued function - Order by is ignored in output
body: <p>We are moving from SQL Server 2008 to SQL Server 2012 and immediately noticed that all our table-valued functions no longer deliver their temp table contents in the correctly sorted order.</p>
  
  <p>CODE:</p>
  
  <pre><code>INSERT INTO @Customer
          SELECT Customer_ID, Name,
          CASE 
              WHEN Expiry_Date &lt; GETDATE() then 1 
              WHEN Expired = 1 then 1 
              ELSE 0
              END
          from Customer **order by Name**
  </code></pre>
  
  <p>In SQL Server 2008 this function returns the customers sorted by Name. In SQL Server 2012 it returns the table unsorted. The <strong>"order by"</strong> is ignored in SQL 2012.</p>
  
  <p>Do we have to re-write all the functions to include a <code>sort_id</code> and then sort them when they are called in the main application or is there an easy fix??</p>