title: How to use multiple values in case statement in SQL server
body: <p>Consider the below </p>
  
  <pre><code>Declare @t table(Val int, name varchar(100))
  Insert into @t select 1,'name1' 
  union all select 1,'name2' 
  union all select 2,'name3'
  union all select 3,'name4'
  </code></pre>
  
  <p>If I want to get the records pertainig to Val 1 or 2 the choice is an IN clause. But we have some condition based on which the values needs to be choosen. Henceforth, we are going ahead with CASE approach as under</p>
  
  <pre><code>declare @type int  = 1
  select *
  from @t 
  where val  = case when @type =1 then 1  end or
        val  = case when @type =1 then 2
               end
  </code></pre>
  
  <p>It works fine as <strong>select * from @t where val in (1,2)</strong>(we cannot use this as the value has to be determined at runtime and we are not using any dynamic query). Is there any other way to simulating the IN clause?</p>
  
  <p>This is just for the sake of knowledge.</p>
  
  <p>Thanks</p>