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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Update Query for one to many mapping.

Author  Topic 

rajikrishna
Starting Member

12 Posts

Posted - 2007-03-24 : 04:58:21
I have 2 Tables PAD and INFO(as shown above). I need to update PAD based on its mapping with INFO. ie if ID of PAD matches with ID of INFO, update the PAD.ID with corresponding INFO.NUMBER

I tried the below query but it was not successfull
UPDATE PADE1
SET PADE1.[Column 0] = (SELECT [Column 4] FROM INFO WHERE INFO.[Column 4] = PADE1.[Column 0])

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-03-24 : 05:04:07
[code]
UPDATE p
SET ID = i.NUMBER
FROM PAD p inner join INFO i
ON p.ID = i.ID
[/code]


KH

Go to Top of Page

rajikrishna
Starting Member

12 Posts

Posted - 2007-03-24 : 05:05:21
I shall give the columns of both my tables for better understanding

Table PAD has the column ID
PAD
a
a
a
b
b
b
c
c
e
f
g
h

Table INFO has the columns ID,Number
ID Number
a 1
b 2
c 3

My Result should be
Table PAD
ID
1
1
1
2
2
2
3
3
e
f
g
h
Go to Top of Page

rajikrishna
Starting Member

12 Posts

Posted - 2007-03-24 : 05:08:54
Thanks a ton! Khtan
Go to Top of Page
   

- Advertisement -