title: T-Sql - Order By on Alphanumeric
body: <p>i have a list of alphanumeric tokens, say <code>'1a', '1b', '02', '03', '10', '11',</code> etc...</p>
  
  <p>Now, what's the best way to do an order by on this list of tokens?</p>
  
  <p>I am getting <code>'1a', '1b', '10', '11', '02', '03',</code> </p>
  
  <p>but i need it to be </p>
  
  <pre><code>'1a', '1b', '02', '03', '10', '11' 
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>ok, i am doing this after the suggestion but it's not working.</p>
  
  <pre><code>declare @tokens table(token varchar(20));
  
  insert into @tokens
  select '1a'
  select '1b'
  select '02'
  select '10'
  
  select * from @tokens
  order by case
   when ISNUMERIC(token) = 1 then right('0000000000'+token+'0',10)
   else right('0000000000'+token,10)
   end
  </code></pre>
  
  <p>I am getting the response as <code>'1b', '02', '10', '1a'</code></p>
  
  <p><strong>UPDATE2</strong></p>
  
  <p>It works after making the following change.</p>
  
  <pre><code>declare @tokens table(token varchar(20));
  
  insert into @tokens
  select '1a'
  insert into @tokens
  select '1b'
  insert into @tokens
  select '02'
  insert into @tokens
  select '10'
  
  
  select token from @tokens
  order by case
   when ISNUMERIC(token) = 1 then right('0000000000'+token+'0',10)
   else right('0000000000'+token,10)
   end
  </code></pre>
  
  <p>Thanks to all of you for your nice ideas.</p>