title: Select iif sql multiple conditions in one result
body: <p>We have multiple variables: Variable1, Variable2, and Variable3 in SQL Server 2012</p>
  
  <p>If one of these variables fail, we out fail status</p>
  
  <pre><code>Declare @Variable1 int
  Set @Variable1 = ( select  top 1 count(*)
  FROM Table1
  where condition1=1 
  group by column1,column2
  having count(1) &gt;1)
  
  Declare @Variable2 int
  Set @Variable2 = ( select  top 1 count(*)
  FROM Table1
  where condition2=1 
  group by column3,column4
  having count(1) &gt;1)
  
  Declare @Variable3 int
  Set @Variable3 = ( select  top 1 count(*)
  FROM Table1
  where condition3=1 
  group by column5,column6
  having count(1) &gt;1)
  
  SELECT IIF ( @Variable1 &gt;=1 and Variable2 &gt;=1 and Variable3 &gt;=1, 'Fail', 'Pass' ) AS ResultTable1;
  </code></pre>
  
  <p>The ResultTable1 always get result base on @Variable1 and not base on @Variable2 and @Variable3 result</p>
  
  <p>Can any one help? -thanks</p>