Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Alter table without destroy variable

Status
Not open for further replies.

chaoma

Technical User
Apr 17, 2005
101
US
I have query like:

Declare @count int
set @count=(select count(*) from table)

Alter table table
Add column1 int

Update table
Set column1=123

When I try to run this query, it complains that column1 does not exist. I can add a “GO” statement after

Alter table table
Add column1 int
GO

, but @count will be destroy.

Is there a way to resolve this problem?

Any help is very much appreciate.

Chaoma.

 
Alter table table
Add column1 int

Declare @count int
set @count=(select count(*) from table)

Update table
Set column1=123

“I sense many useless updates in you... Useless updates lead to defragmentation... Defragmentation leads to downtime...Downtime leads to suffering..Defragmentation is the path to the darkside.. DBCC INDEXDEFRAG and DBCC DBREINDEX are the force...May the force be with you" --
 
How about trying this: Do your alter table first, then do the Count(*)?


Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top