tags:

views:

83

answers:

2

Hi there,

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 checked 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?

Thank you.

+2  A: 

You need to run

exec sp_refreshsqlmodule 'VWProductsCurrent'

to refresh the metadata held about the view.

Martin Smith
as far as I know 'tis not for tables
silent
@silent - I'm assuming that the `VW` prefix is hungarian notation for view.
Martin Smith
he said 'tis table in question
silent
@Silent - No he doesn't. He says there is an **associated** table.
Martin Smith
A: 

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'
silent
Hey, ran the query. It showed 22 results for VWProductsCurrent and number 22 was ContentMarginExVat :S
Neil Bradley
try to recompile your stored proc
silent
Try `SELECT '*' + name + '*' ...` to see if there are any spaces stored in the name...
ck
Awesome. The recompile worked. No longer showing an error. :D
Neil Bradley
VWProductsCurrent is a view using `*` right? And you have recently changed the base table definition to add a new column? If so `exec sp_refreshsqlmodule 'VWProductsCurrent'` is what you need. I guess recompiling the proc probably had the same effect then.
Martin Smith