SQL Server : copying columns to another table based on a join -


i pretty inexperienced when comes sql, apologize if rookie question.

i need add columns table in database, based on join database, using common column between 2 tables.

when "add columns table in database," mean have table, e.g.

create table targets (     targetid int identity(1,1) not null ,         constraint pkc_target primary key clustered ( targetid ) ,     targetfield1 varchar(64) not null ,     ..... ) 

and want add additional columns table? if so, you'd like

alter table dbo.targets add targetnewfield1 varchar(64) null 

after that, you'd have empty columns in table, , run update fill in blanks, like:

update dbo.targets set dbo.targets.targetnewfield1 = dbo.source.sourcefield1 dbo.targets inner join dbo.source on dbo.targets.someuniquefield = dbo.source.someuniquefield 

Comments