title: SQL: case statement in order by clause
body: <p><a href="http://msdn.microsoft.com/en-us/library/ms181765.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/ms181765.aspx</a></p>
  <p>I see the sql below from above link:</p>
  <pre><code>SELECT BusinessEntityID, SalariedFlag
  FROM HumanResources.Employee
  ORDER BY CASE SalariedFlag WHEN 1 THEN BusinessEntityID END DESC
      ,CASE WHEN SalariedFlag = 0 THEN BusinessEntityID END;
  GO
  </code></pre>
  <p>Here is one result I get:</p>
  <blockquote>
  <p>BusinessEntityID,SalariedFlag</p>
  <p>7,1</p>
  <p>5,1</p>
  <p>3,1</p>
  <p>1,1</p>
  <p>2,0</p>
  <p>4,0</p>
  <p>6,0</p>
  <p>8,0</p>
  </blockquote>
  <p>Could anyone explain why the records with same salariedFlag are next to each other and why salariedFlag=1 chunk is above the salariedFlag=0 chunk?</p>