title: SQL Server create ordered #Temp table
body: <p>I try to create ordered #Temp table:</p>
  
  <pre><code>WITH Ordered AS (
  SELECT ROW_NUMBER() OVER (ORDER BY [Quality] DESC) AS RowNumber, ImageID, Quality, Border, IsBest
    FROM [CatalogImages].[dbo].[Images] ORDER BY Quality)
  
  SELECT *
    INTO #Temp
    FROM Ordered ;
  
   SELECT * FROM #Temp ;
  </code></pre>
  
  <p>but I get error:</p>
  
  <blockquote>
    <p>Msg 1033, Level 15, State 1, Line 82<br>
    The ORDER BY clause is invalid
    in views, inline functions, derived tables, subqueries, and common
    table expressions, unless TOP or FOR XML is also specified.</p>
  </blockquote>
  
  <p>How to create ordered temp table?</p>