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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

update question 1

Status
Not open for further replies.

mjd3000

Programmer
Apr 11, 2009
136
GB
I am trying to do an update of a field based where I am getting the data from a join between 2 other tables. Can somebody tell me what is wrong with my syntax below?

update ContactExtensionBase
set New_DateEnquiryTaken = (
SELECT l.createdon
FROM ContactBase c
inner join LeadBase l
on c.OriginatingLeadID = l.LeadID) as z
where ContactID = z.ContactID
 
Code:
update ContactExtensionBase
set New_DateEnquiryTaken = Tb1l.createdon
FROM ContactExtensionBase
INNER JOIN (SELECT [c or l here].ContactID, l.createdon
                  FROM ContactBase c
                  inner join LeadBase l
           on c.OriginatingLeadID = l.LeadID) Tbl1
where ContactExtensionBase.ContactID = Tbl1.ContactID

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
The parenthetical stuff is just clouding the issue. How about this way:
Code:
UPDATE E
SET New_DateEnquiryTaken = L.CreatedOn
FROM
   ContactExtensionBase E
   INNER JOIN ContactBase C ON E.ContactID = C.ContactID
   INNER JOIN LeadBase L ON C.OriginatingLeadID = L.LeadID
That seems a lot easier to understand, to me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top