I\'ve hit a bit of an impasse. I have a query that is generated by some C#
code. The query works fine in Microsoft SQL Server Management Studio
whe
In my case it seems the problem was a weird caching problem. The solutions above didn't work.
If your code was working fine and you added a column to one of your tables and it gives the 'invalid column name' error, and the solutions above doesn't work, try this: First run only the section of code for creating that modified table and then run the whole code.
In my case I was trying to get the value from wrong ResultSet when querying multiple SQL statements.
If you are using variables with the same name as your column, it could be that you forgot the '@' variable marker. In an INSERT statement it will be detected as a column.
Also happens when you forget to change the ConnectionString and ask a table that has no idea about the changes you're making locally.
If you are running this inside a transaction and a SQL statement before this drops/alters the table you can also get this message.
Including this answer because this was the top result for "invalid column name sql" on google and I didn't see this answer here. In my case, I was getting Invalid Column Name, Id1 because I had used the wrong id in my .HasForeignKey statement in my Entity Framework C# code. Once I changed it to match the .HasOne() object's id, the error was gone.