title: How to fix incorrect syntax near keyword 'ORDER'
body: <p>I've got the following SQL and it's giving me <code>Incorrect syntax near keyword 'ORDER'</code> when I try to execute it:</p>
  
  <pre><code>SELECT COUNT(*) AS ID 
  FROM Employees i
    INNER JOIN #WeightedIDs w
    ON (i.ID = w.ID)
  WHERE (i.DepartmentID = 10 and i.ShiftID = 2)
  
  UNION ALL
  
  SELECT i.ID FROM Employees i
    INNER JOIN #WeightedIDs w
    ON (i.ID = w.ID)
  WHERE (i.DepartmentID = 10 and i.ShiftID = 2)
  ORDER BY w.[Weight] ASC
  </code></pre>
  
  <p>How should I fix it?</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Here's what I'm actually trying to accomplish. I have a SPROC that is generating the query dynamically based on a bunch of different conditions. It also builds a temp table that contains ID's and weights associated with those id's so I would like the results sorted by that. Once the query is generated, I would like to get the count as well as the id's found returned in a list.</p>