Whenever this happens to me, I press Ctrl+Shift+R which refreshes intellisense, close the query window (save if necessary), then start a new session which usually works quite well.
I was getting the same error when creating a view.
Imagine a select query that executes without issue:
select id
from products
Attempting to create a view from the same query would produce an error:
create view app.foobar as
select id
from products
Msg 207, Level 16, State 1, Procedure foobar, Line 2
Invalid column name 'id'.
For me it turned out to be a scoping issue; note the view is being created in a different schema. Specifying the schema of the products table solved the issue. Ie.. using dbo.products instead of just products.
I just tried.
If you execute the statement to generate your local table, the tool will accept that this column name exists.
Just mark the table generation statement in your editor window and click execute.
There can be many things:
First attempt, make a select of this field in its source table;
Check the instance of the sql script window, you may be in a different instance;
Check if your join is correct;
Verify query ambiguity, maybe you are making a wrong table reference
Of these checks, run the T-sql script again
[Image of the script SQL][1]
[1]: https://i.stack.imgur.com/r59ZY.png`enter code here
I noted that, when executing joins, MSSQL will throw "Invalid Column Name" if the table you are joining on is not next to the table you are joining to. I tried specifying table1.row1 and table3.row3, but was still getting the error; it did not go away until I reordered the tables in the query. Apparently, the order of the tables in the statement matters.
If you are going to ALTER Table column and immediate UPDATE the table including the new column in the same script. Make sure that use GO command to after line of code of alter table as below.
ALTER TABLE Location
ADD TransitionType SMALLINT NULL
GO
UPDATE Location SET TransitionType = 4
ALTER TABLE Location
ALTER COLUMN TransitionType SMALLINT NOT NULL
I came here because I was getting this error. And the reason was that I was using double quotes (") instead of single quotes (') when giving values for WHERE conditions. Writing this for the future me.
I experienced similar problem when running a query from the code (C#) side. The column in the table that was bringing the above error had 'default value or binding' (when I checked the table's design) already added. So I just removed the column and its corresponding value as data being inserted by the query