title: t sql - Subquery into variable
body: <p>I can't seem to figure out how to load the value returned by the following expression/subquery into a variable:</p>
  
  <pre><code>declare @var int
  set @var = null
  
    IF @var IS NULL
  SELECT @var = t.col_one
      FROM my_table t
      WHERE t_datetime = (SELECT MAX(t_datetime) FROM t WHERE t.col_two = 1)
  </code></pre>
  
  <p>How can I load the result of the expression into the variable?</p>
  
  <p>I've updated the code to reflect answers below however the issue has persisted. There are no errors but later in my sproc when I call <code>@var</code> the variable is still null. Which means this still isn't working. Later in the code I'm using:</p>
  
  <pre><code>t.col_three = @var
  </code></pre>
  
  <p>Further I'm not using <code>t.col_three = @var or @var is null</code> because the variable cannot be null:</p>