开发者

Invalid column name SQL Server bug

I have a stored procedure that is throwing an 'Invalid column name' error for 'ContentMarginExVat';

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

I have check开发者_C百科ed both the VWProductsCurrents and the associated table that gets the data, both of these have the ContentMarginExVat selected, but yet the SQL Server Management Studio 2008 still says that the Column has an invalid name.

Wondered if anyone might be able to offer any advice on this?


I had this problem with a query generated by SSMS when I selected "Select First 1000 Rows". Red squiggles under my column names and under my table name. But the query executed instantly and displayed the correct data.

After some Googling I found this link.

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


You need to run

exec sp_refreshsqlmodule 'VWProductsCurrent'

to refresh the metadata held about the view.


Try to execute this query and copy the column name to your query:

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

or try to recompile your stored procedure with:

exec sp_recompile 'your_proc_name'


i got this error when made changes on my backend but with a connection that was pointing 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... ;-)


Rename object_id to id

Ctrl+ Shift+R did not work for me even though it removed the squiggly lines and neither did silent's answer. After observing the script, I though maybe the name object_id was being confused with the function OBJECT_ID. I changed the object_id to id and it worked fine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜