title: How to give ranks to multiple columns data in SQL Server?
body: <p>I have input table as shown below -</p>
  
  <pre><code>ID  Name q1     q2      q3      q4
  1   a    2621   2036    1890    2300
  2   b    18000  13000   14000   15000
  3   c    100    200     300     400
  </code></pre>
  
  <p>I want ranking of columns(<code>q1, q2, q3 and q4</code>) data for each row. For example, if I consider last row of above input, then <code>q4</code> column contains <code>400</code> value which is higher than other columns, so rank to <code>q4</code> column will be <code>1</code>, <code>q3</code> rank will be <code>2</code>, <code>q2</code> rank will be <code>3</code> and <code>q1</code> rank will be <code>4</code>.</p>
  
  <p>I am looking for output like -</p>
  
  <pre><code>id  name  q1  q2  q3  q4
  1   a     1   3   4   2
  2   b     1   4   3   2
  3   c     4   3   2   1
  </code></pre>
  
  <p>There are more than 100,000 records present in input table.</p>
  
  <p>I have created small SQL script for input table i.e.,</p>
  
  <pre><code>declare @temp table (ID int, Name varchar(10), q1 int, q2 int, q3 int, q4 int)
  
  insert into @temp
  select 1, 'a', 2621, 2036, 1890, 2300
  union all
  select 2, 'b', 18000, 13000, 14000, 15000
  union all
  select 3, 'c', 100, 200, 300, 400
  
  select * from @temp
  </code></pre>
  
  <p>Please help me to find efficient way to solve this problem.</p>