title: SQL Server Order By (Select Clause from Table)
body: <p>I have this query below, it compiles and runs but doesn't do the job of sorting.</p>
  
  <pre><code>declare @sort table (sort varchar (500))
  insert into @sort values ('Code DESC')
  
  SELECT * FROM  Registry
  ORDER BY (select sort from @sort)
  </code></pre>
  
  <p>Is the approach OK?</p>
  
  <p>If I need to select the sort clause of order by from a table where its stored as string what can be the options or this is a lost cause.</p>
  
  <p>Actually I have a sort table with various bit values (6 columns of bit values) and using those permutations in a CASE WHEN wouldn't be comprehendable, and I cannot use Dynamic SQL</p>