title: SQL Distinct /Order By error
body: <p>I've got a problem when using "order by" &amp; "distinct" at the same time. For example, I have the following:</p>
  
  <pre><code>DECLARE @fieldSort varchar(100) = 'ref'
  
  SELECT DISTINCT EXT_Design_Standard_ID
  FROM EXT_Design_Standard_Change_Log
  ORDER BY CASE 
       WHEN @fieldSort ='REF' THEN 
            EXT_Design_Standard_ID 
       END
  </code></pre>
  
  <p>I get the error of: </p>
  
  <blockquote>
    <p>ORDER BY items must appear in the select list if SELECT DISTINCT is specified.</p>
  </blockquote>
  
  <p>Anyone know how to sort this out?</p>