title: T-SQL: Pick a row where the value in a column is equal to, greater than or less than - but only one of these
body: <p>I have a table, called TableA with the following data in column ColA</p>
  
  <pre><code>ColA
  100
  60
  50
  30
  10
  </code></pre>
  
  <p>I have a parameter called @colA</p>
  
  <p>I want to select only one row. The criteria is such that if the value of ColA matches @colA, that row is returned. If no match is found, then it looks for the row where the difference between ColA and @colA is the smallest.</p>
  
  <p>For example, if @colA = 50, the row with 50 is returned. If @colA = 58, the row with 60 is returned. If @colA = 33, the row with 30 is returned. If @colA = 200, the row with 100 is returned. Can this be done just using a Where clause and/or some Min/Max statements in the Select statement or would it be better off to be done with IF statements testing each condition?</p>
  
  <p>Thanks for your help!</p>