Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update table using joins

Status
Not open for further replies.

TysonLPrice

Programmer
Jan 8, 2003
859
US
I'm having trouble putting together an update. The query to select the data is:

Code:
select  c.coordinator,  x.coordinator
from ##Xref x, Claim c (nolock) 
join iwlocation (nolock) on fkiwlocation = pkiwlocation
join injuredworker iw (nolock) on fkinjuredworker = pkinjuredworker
where fkemployeraddress = 47556
and iw.SSN = x.SSN[\code]

I neeed to set the Claim table coordinator (c.coordinator)to the ##XREF table coordinator (x.Coordinator) using the same look up logic.

I can't seem to get.  Can somebody help me out?
 
Code:
;with cte as (select c.PK, c.coordinator,  x.coordinator as NewCoordinator
from ##Xref x , Claim c (nolock) -- What is the join condition between these two - do you want a cross join ?
join iwlocation (nolock) on fkiwlocation = pkiwlocation
join injuredworker iw (nolock) on fkinjuredworker = pkinjuredworker
where fkemployeraddress = 47556
and iw.SSN = x.SSN)

update cte set Coordinator = NewCoordinator

PluralSight Learning Library
 
Code:
update c
set coordinator=  x.coordinator
--select  c.coordinator,  x.coordinator
from ##Xref x
join Claim c (nolock) 
     on ?
join iwlocation (nolock) 
     on fkiwlocation = pkiwlocation
join injuredworker iw (nolock) 
     on fkinjuredworker = pkinjuredworker
where fkemployeraddress = 47556
     and iw.SSN = x.SSN
Never use implied joins, this one would give you a cross join which I cannot think you would want for an update. Implied joins are an exterely poor practice and implied joins combined with explicit joins can create some strange results.

"NOTHING is more important in a database than integrity." ESquared
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top