title: Make a SQL Server script compile including a column that doesn't exist?
body: <p>I have an SQL script that's run as a migration on a database before a column is dropped. It works fine the first time because the source column exists, but it fails if you try to run the migration again, because now the column doesn't exist. I wrapped it in an IF, so the statement is only run if the column does exist, but it still needs to be able to compile that bit, even though I know it won't run it.</p>
  <p>Here's a simplified version:</p>
  <pre><code>IF COL_LENGTH('TableA', 'SourceColumn') IS NOT NULL
  BEGIN
      UPDATE TableB
      SET DestColumn = TableA.SourceColumn
      FROM TableB
      JOIN TableA AS ON TableB.AId = TableA.Id
      WHERE TableB.DestColumn != TableA.SourceColumn;
  END
  
  ALTER TABLE TableA 
  DROP COLUMN SourceColumn;
  </code></pre>