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.

 All Forums
 Old Forums
 CLOSED - General SQL Server
 Update table query

Author  Topic 

drpkrupa
Yak Posting Veteran

74 Posts

Posted - 2006-05-11 : 13:28:21
I have two table called Table A and Table B
Table A (Columns - ID, Last , First)
Table B (Columbs - ID, Last, First, Address)

Data into tables
Table A
1 , ,
2, ,
3, ,

Table B
1,AA,BB,679
2,BB,CC,500
3,LL,MM,600

I would like to write update query to update table A with last name and first name column fill from Table B when TableA.ID = TableB.ID
How can i write update query to fill table A from getting data from TableB


I need result for Table A
1,AA,BB
2,BB,CC
3,LL,MM

Thanks,

Kristen
Test

22859 Posts

Posted - 2006-05-11 : 13:45:48
[code]
UPDATE A
SET Last = B.Last,
First = B.First
FROM dbo.TableA AS A
JOIN dbo.TableB AS B
ON B.ID = A.ID
[/code]
Kristen
Go to Top of Page

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-05-11 : 13:48:16
[code]Update TableA
Set Last = b.Last, First= b.First
from TableA a inner join TableB b on a.ID= b.ID[/code]

Edit :
I'm a bit late than Kristen
Also, there are examples similar to this if u search for UPDATE in Books ONline (SQL Server Help)

Srinika
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-05-12 : 02:15:33
As in Kristen's query use Alias name after keyword Update

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -