Friday, March 9, 2012

invalid column error when updating a new column that was added by alter table

i am getting an error "Invalid Column name <column name>" message when runni
ng an update statement which updates a new column which was just added by an
alter table statement. If i run the alter statement and update statement se
perately, i don't get any e
rrors and it works. I only get this when they run together in a script or st
ored proc.
Is this a bug and what are the alternatives. Thanks.This is the way that the parser work. As the column doesn't (yet) exists at
parse time, the update will
generate the error. One way around it is to do the update with dynamic SQL.
OTOH, I'd re-consider why you have
to add a column dynamically in the first place (if possible).
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"jsin" <anonymous@.discussions.microsoft.com> wrote in message
news:6A977D73-49D1-4229-92B1-B90B8E054540@.microsoft.com...
> i am getting an error "Invalid Column name <column name>" message when running an
update statement which
updates a new column which was just added by an alter table statement. If i
run the alter statement and update
statement seperately, i don't get any errors and it works. I only get this w
hen they run together in a script
or stored proc.
> Is this a bug and what are the alternatives. Thanks.

No comments:

Post a Comment