title: Dynamic TOP N / TOP 100 PERCENT in a single query based on condition
body: <p>A local variable <code>@V_COUNT</code> <code>INT</code>. If the variable <code>@V_COUNT</code> is <code>'0'</code>(zero) the return all the records from table otherwise return the number of <code>{@V_COUNT}</code> records from table. For example if <code>@V_COUNT = 50</code>, return <code>TOP 50</code> records. If <code>@V_COUNT</code> is <code>0</code> then return <code>TOP 100 PERCENT</code> records. Can we achieve this in a single query?</p>
  
  <p>Sample query :</p>
  
  <pre><code>DECLARE @V_COUNT INT = 0
  
  SELECT  TOP (CASE WHEN @V_COUNT &gt; 0 THEN  @V_COUNT ELSE  100 PERCENT END) *
  FROM    MY_TABLE
  ORDER BY COL1
  </code></pre>
  
  <blockquote>
    <p>Incorrect syntax near the keyword 'percent'</p>
  </blockquote>