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 2000 Forums
 Transact-SQL (2000)
 Update Statement Syntax

Author  Topic 

Jonny1409
Posting Yak Master

133 Posts

Posted - 2007-10-15 : 06:47:12
Hello,

I have a table with the following fields :

Name = e.g. Joe Bloggs
Age = 27
DOB = 01/01/1980
AreaID = NULL
AreaName = North West

Every person listed in here has a

I have another table which lists the areas (ID and Name)

1 - North
2 - South
3 - North West
and so on....

I would like to update every person's record in table 1, with their team ID as currently it is null.

Obviously I need to get the team ID using table 2 and linking on the name.

What would be the syntax for this please ?

Thanks in advance

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-10-15 : 06:51:28
update x
set x.areaid = y.id
from table1 as x
inner join table2 as y on y.name = x.areaname



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-10-15 : 06:52:18
[code]UPDATE p
SET areaid = a.id
FROM person p INNER JOIN area a
ON p.areaname = a.name
WHERE p.areaid IS NULL[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-10-15 : 06:53:11
!

where is the alert ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

Jonny1409
Posting Yak Master

133 Posts

Posted - 2007-10-15 : 06:57:58
Thanks Peso and Khtan
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-10-15 : 07:23:55
quote:
Originally posted by khtan

!

where is the alert ?


KH
[spoiler]Time is always against us[/spoiler]




Your color coding tool takes lot of time

Madhivanan

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

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-10-15 : 07:27:10
yeah, slow by 50 seconds


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -