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 |
|
newuser12
Starting Member
6 Posts |
Posted - 2009-03-10 : 06:28:52
|
| I have following 2 tables Table1ID Amt AmtType1 100 Amt12 200 Amt13 300 Amt23 300 Amt34 800 Amt1Table2 - Currently type in Table2 iS NULLID Amt AType1 100 NULL2 200 NULL3 300 NULL3 300 NULL4 800 NULLI want to update AType of Table2 from AmtType of Table1. My output should be as followTable2 - ID Amt AType1 100 Amt12 200 Amt13 300 Amt23 300 Amt34 800 Amt1I am facing problem to update the AType for ID = 3.Could you please suggest,how I can update Table2 this? |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-03-10 : 06:30:42
|
| update tset t.atype= a.amttypefrom table2 tinner join table1 a on a.id = t.id and a.amt= t.amt |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-03-10 : 06:35:03
|
| [code]UPDATE t1SET t1.AType=t2.AmtTypeFROM (SELECT ROW_NUMBER() OVER (PARTITION BY ID,Amt ORDER BY ID) AS Seq,ID,Amt,ATypeFROM Table2)t1JOIN (SELECT ROW_NUMBER() OVER (PARTITION BY ID,Amt ORDER BY ID) AS Seq,ID,Amt,AmtTypeFROM Table1)t2ON t2.ID=t1.IDAND t2.Seq=t1.SeqAND t2.Amt=t1.Amt[/code] |
 |
|
|
|
|
|