title: IF ELSE Statement in SQL
body: <pre><code>SELECT S.Id, S.Name, S.Version, S.SoftNo
  FROM SOFTWARE S WITH(NOLOCK)
  WHERE (IF S.Version = 0 THEN S.Version &gt; 0 ELSE S.Version = @Version)
  AND (IF S.SoftNo = 0 THEN S.SoftNo &gt; 0 ELSE S.SoftNo = @SoftNo)
  </code></pre>
  
  <p>If Version is equal to zero, I want to list everything version number is greater then 0 if it is not equal to 0, then Version should be whatever it is value.</p>
  
  <p>This is same for SoftNo.</p>
  
  <p>How can I fix my SQL query. It just doesn't work.</p>
  
  <p>More details:</p>
  
  <p>This is what I want to achieve:</p>
  
  <pre><code>if(Version == 0)
  {
       display every single rows if their version number is greater then 0;
  }
  else
  {
       Lets assume that Version is equal to 5. Then just display the rows if their Version number is equal to 5;
  } // This is like a C# code of what I am trying to do in my sql query.
  </code></pre>