I am trying to copy rows from one column to another. Execution flow is simple.

1. Check if column is exist.
2. If not - add column
3. Define cursor and populate rows for new column
4. Set column to NOT NULL.

Unfortunately I am getting this type of error. It says that column does not exist. But I've created it and committed transaction. What could be a reason? Thanks! 

> 
> Msg 207, Level 16, State 1, Line 29  
> 
>  Invalid column name 'Field\_Name'.
> 
> 
> 

Code:

```
begin transaction;

IF NOT EXISTS(SELECT * FROM sys.columns 
                WHERE Name = N'Field_Name' and Object_ID = Object_ID(N'dbo.Table_Name'))
BEGIN
        ALTER TABLE [dbo].[Table_Name]
        ADD [Field_Name] VARCHAR(255)
END
commit;

DECLARE
    @var1 int,
    @var2 varchar(255)

DECLARE copy_cursor CURSOR FOR 
    SELECT id, Name
    FROM Table_Name

OPEN copy_cursor

FETCH NEXT FROM copy_cursor 
    INTO @var1, @var2

WHILE @@FETCH_STATUS = 0
BEGIN
   UPDATE Table_Name
   SET Field_Name = @var2
   WHERE id = @var1

   FETCH NEXT FROM copy_cursor 
      INTO @var1, @var2
END

CLOSE copy_cursor;
DEALLOCATE copy_cursor;

ALTER TABLE Table_Name ALTER COLUMN Field_name varchar(255) NOT NULL

```