title: How to use case when in where conditon tsql?
body: <p>Following is the part of a stored procedure:-</p>
  
  <pre><code>@ID int
  @Col1 int
  @Col2 int
  
  Select * 
  from Table_01 t1
  JOIN table_02 t2 on t1.col = t2.col
  where 
    1 = case when @Col1 = 0 then 1 else (case when t2.Col1 = @Col1 then 1 else 0 end) end
    AND 1 = case when @Col2 = 0 then 1 else (case when t2.Col2 = @Col2 then 1 else 0 end) end
    AND 1 = case when @ID = 0 then 1 else (case when t2.ID = @ID then 1 else 0 end) end
  </code></pre>
  
  <p>Currently </p>
  
  <ul>
  <li>if <code>@ID = 0</code> then it ignores the condition</li>
  <li>if @ID has value then it returns results based on the criteria satisfaction</li>
  </ul>
  
  <p>I need to add another condition there :-</p>
  
  <p><code>if @ID = -1</code> then should not return any result (coz there is no match) 
  but it should act like <code>@ID = 0</code> (ignore to add expresssion)</p>
  
  <p>Am I clear? :(</p>