Hi guys,I've come across some odd behaviour when trying to add a field programmatically, and wondered if anyone else has come across this (or if I'm doing something wrong I haven't spotted of course
)The basic outline of what I want to do is as follows:I have two tables each of which has a bit field, the first table references the second by an ID field. I want to move the bit field from table 2 into table 1, and I am trying to do this by creating a new field then using an UPDATE..FROM.. query to insert all the corresponding values.When I run each query separately they perform as expected, however when I run them together in a batch SQL Server doesn't seem to acknowledge the new field exists. The commands below replicate the error - I am using Query Analyser in SQL Server 2000:CREATE TABLE #temp1 (tid INTEGER NOT NULL, t1flag BIT NOT NULL)INSERT INTO #temp1 (tid, t1flag) VALUES (1, 1)INSERT INTO #temp1 (tid, t1flag) VALUES (2, 1)INSERT INTO #temp1 (tid, t1flag) VALUES (3, 0)INSERT INTO #temp1 (tid, t1flag) VALUES (4, 1)INSERT INTO #temp1 (tid, t1flag) VALUES (5, 0)INSERT INTO #temp1 (tid, t1flag) VALUES (6, 1)INSERT INTO #temp1 (tid, t1flag) VALUES (7, 1)INSERT INTO #temp1 (tid, t1flag) VALUES (8, 0)INSERT INTO #temp1 (tid, t1flag) VALUES (9, 0)INSERT INTO #temp1 (tid, t1flag) VALUES (10, 1)CREATE TABLE #temp2 (tid INTEGER NOT NULL, t2flag BIT NOT NULL)INSERT INTO #temp2 (tid, t2flag) VALUES (1, 1)INSERT INTO #temp2 (tid, t2flag) VALUES (2, 1)INSERT INTO #temp2 (tid, t2flag) VALUES (3, 1)INSERT INTO #temp2 (tid, t2flag) VALUES (4, 1)INSERT INTO #temp2 (tid, t2flag) VALUES (5, 1)INSERT INTO #temp2 (tid, t2flag) VALUES (6, 1)INSERT INTO #temp2 (tid, t2flag) VALUES (7, 1)INSERT INTO #temp2 (tid, t2flag) VALUES (8, 1)INSERT INTO #temp2 (tid, t2flag) VALUES (9, 1)INSERT INTO #temp2 (tid, t2flag) VALUES (10, 1)ALTER TABLE #temp2 ADD t1flag BIT NULLUPDATE #temp2 SET t1flag = t1.t1flag FROM #temp1 t1 WHERE #temp2.tid = t1.tidSELECT * FROM #temp2
Any ideas what is happening?Steve