title: Invalid column name on sql server update after column create
body: <p>Does anyone see what's wrong with this code for SQL Server?</p>
  
  <pre><code>IF NOT EXISTS(SELECT *
                FROM   sys.columns
                WHERE  Name = 'OPT_LOCK'
                       AND object_ID = Object_id('REP_DSGN_SEC_GRP_LNK'))
    BEGIN
        ALTER TABLE REP_DSGN_SEC_GRP_LNK
          ADD OPT_LOCK NUMERIC(10, 0)
  
        UPDATE REP_DSGN_SEC_GRP_LNK
        SET    OPT_LOCK = 0
  
        ALTER TABLE REP_DSGN_SEC_GRP_LNK
          ALTER COLUMN OPT_LOCK NUMERIC(10, 0) NOT NULL
    END; 
  </code></pre>
  
  <p>When I run this, I get:</p>
  
  <blockquote>
    <p>Msg 207, Level 16, State 1, Line 3<br>
    Invalid column name 'OPT_LOCK'.</p>
  </blockquote>
  
  <p>on the update command.</p>
  
  <p>Thanks.</p>