Reputation: 8552
I'm using a script like the following, but it keeps complaining of an Invalid column name 'NewColumnA' . Is dynamic sql necessary to accomplish this, or is there an easier solution?
ALTER TABLE TableA ADD NewColumnA VARBINARY(300)
UPDATE TableA
SET
NewColumnA=b.OldColumnB,
FROM
TableA a, TableB b
WHERE a.myID=b.myID
Upvotes: 0
Views: 1119
Reputation: 33809
You need to add Go
(which Signals the end of a batch of Transact-SQL statements
) after ALTER TABLE
;
ALTER TABLE TableA ADD NewColumnA VARBINARY(300)
GO
--rest of the query
UPDATE TableA
SET
NewColumnA=b.OldColumnB,
FROM
TableA a, TableB b
WHERE a.myID=b.myID
Upvotes: 3
Reputation: 16351
Try with a GO
:
ALTER TABLE TableA ADD NewColumnA VARBINARY(300)
GO
UPDATE TableA
SET
NewColumnA=b.OldColumnB,
FROM
TableA a, TableB b
WHERE a.myID=b.myID
Upvotes: 2