TSQL - MSSQL 2008 add a column and update it in same stored procedure
- by TortTupper
if I have a stored procedure say
create procure w AS
ALTER TABLE t ADD x char(1)
UPDATE t set x =1
Even when it lets me create that stored procedure (if I create it when x exists), when it runs, there is an error on the UPDATE statement because column x doesn't exist.
What's the conventional way to deal with this, it must come up all the time? I can work around it by putting the UPDATE inside EXEC, is there another/better way?
Thanks