Reputation: 41
I want to copy a column from one table to another.
The number of rows is equal in both tables. The values I want to copy from table2 to table1 are unique. I've tried a few thing, but none so far work. My code is:
insert into alleoppdragpunkter3
select Idtall
from IDtall
Msg 2809, Level 16, State 1, Line 2 The request for procedure 'IDtall' failed because 'IDtall' is a table object.
I would like my column from table2 to be in table1.
Upvotes: 0
Views: 429
Reputation: 1269463
You do not copy columns between tables. You can insert rows and update columns.
Perhaps you want:
update p
set p.<col> = i.<col>
from alleoppdragpunkter3 p join
idtall i
on p.? = i.?;
The ?
is for the column that specify the join
conditions between the tables. The set
references the column you want to update and which value to take.
Upvotes: 0
Reputation: 37473
You can try below-
insert into alleoppdragpunkter3(col1,col2,col3,....)
select col1,col2,col3,.... from IDtall
Upvotes: 2