Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
nic
Posting Yak Master
209 Posts |
Posted - 2003-11-07 : 17:04:14
|
Hi,I'm at a loss on how to do this (I'm sure the answer is very simple). I need to update a record in a table with a different record in the same table. UPDATE Persons SET FirstName = b.FirstName ,MiddleName = b.MiddleName ,LastName = b.LastName ,Suffix = b.SuffixFROM Persons, Persons bWHERE PersonID = 158 -- new record AND b.PersonID = 159 -- original record Essentially I need to override the 158 record with data from the 159 record. I keep getting an Ambiguous column errorNic |
|
|
ehorn
Master Smack Fu Yak Hacker
1632 Posts |
Posted - 2003-11-07 : 17:23:41
|
| [code]create table #test (n int,data char(4))goinsert into #test select 0,'DAT0' union select 1,'DAT1'select * from #testupdate #test set data = a.data from #test t1,(select t2.data from #test t2 where t2.n = 1) a where t1.n =0 goselect * from #testdrop table #test[/code] |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2003-11-07 : 17:42:42
|
| [code]UPDATE PersonsSET FirstName = b.FirstName ,MiddleName = b.MiddleName ,LastName = b.LastName ,Suffix = b.SuffixFROM Persons a, (SELECT FirstName, MiddleName, LastName, Suffix FROM Persons WHERE PersonID = 158) b WHERE a.PersonID = 159[/code]Tara |
 |
|
|
|
|
|
|
|