title: SQL Server : dynamic order by sort by asc
body: <p>I have a SQL query that I'm running with a conditional order by statement.</p>
  <p>I'm trying to order by desc with nulls last, however my query returns the results not in asc order.</p>
  <p>Here's an example:</p>
  <pre><code>DECLARE @Sort varchar(300);
  SET @Sort = 'UngradedDescription asc'
  
  SELECT 
      [UngradedDescription]
  FROM 
      [dbo].[CardListing_Staging]
  ORDER BY
      CASE 
          WHEN @Sort = 'UngradedDescription asc' 
              THEN ((CASE WHEN UngradedDescription IS NULL THEN 1 ELSE 0 END))
      END 
  </code></pre>
  <p>These are the results I get:</p>
  <p><a href="https://i.stack.imgur.com/anViJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/anViJ.png" alt="enter image description here" /></a></p>
  <p>How can I get them in asc order 02... 04... 06... nulls?</p>