Invalid SQL Server Error Column Name

I have a stored procedure that throws an "Invalid column name" error for "ContentMarginExVat";

SELECT CategoryTitle, ContentID, ContentTitle, ContentMarginExVat, ContentWeight FROM VWProductsCurrent WHERE ContentID = @ContentID 

I checked both VWProductsCurrents and the related table that receives the data, both of them have the selected ContentMarginExVat, but SQL Server Management Studio 2008 still says the column has an invalid name.

I wonder if anyone can offer any advice on this?

Thanks.

+4
source share
5 answers

Try this query and copy the column name into your query:

 select name from sys.columns where object_id = object_id('VWProductsCurrent') 

or try recompiling the stored procedure with:

 exec sp_recompile 'your_proc_name' 
+2
source

I had a problem with a query created by SSMS when I selected "Select the first 1000 rows." Red squiggles under my column names and under my table name. But the query runs instantly and displays the correct data.

After some googling, I found this link .

I pressed Ctrl-Shift-R to refresh the cache. Nothing happened right away, but after about 5-6 seconds, the squiggles went to two tables, where I had this problem.

+6
source

You need to run

 exec sp_refreshsqlmodule 'VWProductsCurrent' 

to update the metadata stored in the view.

+4
source

I got this error when making changes on my server, but with a connection that pointed to another copy of the backend that was not updated, so I just had to change the connection string to the updated backend, and it worked ...; -)

0
source

Rename object_id to id

Ctrl + Shift + R did not work for me, although it deleted squiggly lines and didn’t say a reply. After observing the script, although perhaps the name object_id was confused with the OBJECT_ID function. I changed object_id to id and it worked fine.

0
source

Source: https://habr.com/ru/post/1314826/


All Articles