title: How can I get column name based on row value in SQL Server?
body: <p>I got an lookup table with a lot of columns with values.
  How can I get this output from the input using Microsoft SQL Server?<br />(Basically select the column name where Date = MAX() AND ColX to ColZ value =&lt; 5.4).</p>
  
  <ol>
  <li>Find the row with the latest date. MAX(Date)</li>
  <li>Look in ColX, is my value 5.4 higher than ColX's value? Y/N</li>
  <li>Yes. Look in ColY, is my value 5.4 higher than ColY's value? Y/N</li>
  <li>Yes. Look in ColZ, is my value 5.4 higher than ColZ's value? Y/N</li>
  <li>No. Output Column ColY AS Column</li>
  </ol>
  
  <p><strong>Input</strong></p>
  
  <pre>
  ID        Date                 ColX    ColY    ColZ
  -----------------------------------------------------
  79185673  2018-11-28 00:00:00     3       5       7
  79185673  2018-12-02 00:00:00     2       4       6
  79185673  2018-12-04 00:00:00     4       5       6
  </pre>
  
  <p><strong>Output</strong></p>
  
  <pre>
  ID        Date                 Column 
  --------------------------------------
  79185673  2018-12-04 00:00:00    ColY
  </pre>