June 2, 2011 at 11:18 am
SQL 2008
Not sure how to do this, I have 2 tables, each with the exact same identity column. Table2 has 3 new columns I would like to insert into Table1, matching up the rows by the identity column.
So something like: insert into table1 (table2.column4, table2.column5, table2.column6) where table1.ID = table2.ID
just not sure of the correct syntax, any help is greatly appreciated.
June 2, 2011 at 11:56 am
Try this:
UPDATE T1
SET
T1.column4 = T2.column4,
T1.column5 = T2.column5,
T1.column6 = T2.column6
FROM
table1 T1 inner join table2 T2
on table1.ID = table2.ID
June 6, 2011 at 9:00 am
awesome! Thanks so much
June 6, 2011 at 9:02 am
The Merge command is, in some ways, better than Update From, in SQL 2008. Check out Merge when it comes to synchronizing data like this.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply