title: Using an equality check between columns in a SELECT clause
body: <p>I am using Microsoft SQL Server 2012 and I would like to run this seemingly simple query:</p>
  
  <pre><code>SELECT 
      FirstEvent.id AS firstEventID, 
      SecondEvent.id AS secondEventID, 
      DATEDIFF(second, FirstEvent.WndFGEnd, SecondEvent.WndFGStart) AS gap, 
      FirstEvent.TitleID = SecondEvent.TitleID AS titlesSameCheck
  FROM VibeFGEvents AS FirstEvent
  RIGHT OUTER JOIN VibeFGEvents AS SecondEvent
  ON 
      FirstEvent.intervalMode = SecondEvent.intervalMode 
      AND FirstEvent.id = SecondEvent.id - 1 
      AND FirstEvent.logID = SecondEvent.logID
  </code></pre>
  
  <p>However <code>FirstEvent.TitleID = SecondEvent.TitleID AS titlesSameCheck</code> in the <code>SELECT</code> clause is incorrect syntax. But <a href="http://msdn.microsoft.com/en-gb/library/ms176104.aspx">the SELECT Clause (Transact-SQL) documentation</a> includes this syntax:</p>
  
  <pre><code>SELECT [ ALL | DISTINCT ]
  [ TOP ( expression ) [ PERCENT ] [ WITH TIES ] ] 
  &lt;select_list&gt; 
  &lt;select_list&gt; ::= 
      { 
          * 
          | { table_name | view_name | table_alias }.* 
          | {
              [ { table_name | view_name | table_alias }. ]
                  { column_name | $IDENTITY | $ROWGUID } 
              | udt_column_name [ { . | :: } { { property_name | field_name } 
              | method_name ( argument [ ,...n] ) } ]
              | expression
              [ [ AS ] column_alias ] 
              }
          | column_alias = expression 
      } [ ,...n ]
  </code></pre>
  
  <p>I think that means an expression is valid in the select clause and indeed the examples given include things like <code>1 + 2</code>. Looking at <a href="http://msdn.microsoft.com/en-gb/library/ms190286.aspx">the documentation for expressions</a>:</p>
  
  <pre><code>{ constant | scalar_function | [ table_name. ] column | variable 
      | ( expression ) | ( scalar_subquery ) 
      | { unary_operator } expression 
      | expression { binary_operator } expression 
      | ranking_windowed_function | aggregate_windowed_function
  }
  </code></pre>
  
  <p>boolean equality checks are valid expressions and indeed the example expression given in <a href="http://msdn.microsoft.com/en-us/library/ms175118.aspx">the = (Equals) (Transact-SQL) documentation</a> includes one:</p>
  
  <pre><code>SELECT DepartmentID, Name
  FROM HumanResources.Department
  WHERE GroupName = 'Manufacturing'
  </code></pre>
  
  <p>albeit in the <code>WHERE</code> clause not the <code>SELECT</code> clause. It looks like I cannot use <code>=</code> the equality operator to compare expressions in my <code>SELECT</code> clause as they are being wrongly interpreted as assignment.</p>
  
  <p>How do I include a Boolean equality column comparison equivalent to <code>FirstEvent.TitleID = SecondEvent.TitleID AS titlesSameCheck</code> in my <code>SELECT</code> clause?</p>