title: Assigning a variable conditionally inside a SELECT statement on SQL SERVER
body: <p>I am attempting to write a <code>SELECT</code> statement on SQL Server that displays items based on a condition, which I provide in the subsequent <code>WHERE</code> clause. </p>
  
  <p>Here is a simplified version of what I am attempting to write.</p>
  
  <pre><code>DECLARE @tmpvar varchar(5)
  ....
  
  SELECT @tmpvar,
  ....
  FROM some_table
  WHERE 
  ....
  and @tmpvar =
        CASE WHEN (some condition here)
               THEN 'YES'
               ELSE 'NO'
        END
  </code></pre>
  
  <p>The code above executes successfully, but when I check the value of <code>@tmpvar</code>, it remains unassigned. </p>
  
  <p>I'd like to know if there is a mistake in the syntax I am using. If so, what would be the correct way of assigning the variable inside the <code>SELECT</code> statement using the given condition? Prior apologies if this question is redundant.</p>