Page 1 of 1

Salesforce Update with Join clause

Posted: Thu 01 Feb 2018 15:42
by pherschel
I'm trying to perform an update where I join two tables:

UPDATE Contact
inner join Account on Account.Id = Contact.AccountId
set Contact.OwnerID = '00538000004tIuhAAE'
WHERE (Account.Type <> 'Prospect') and contact.mailingstate in ('ND', 'SD') and contact.OwnerID <> '00538000004tIuhAAE'

I get an error: You have an error in your SQL syntax at line 2, column 1: keyword 'set' expected

I've also tried:

UPDATE Contact
set Contact.OwnerID = '00538000004tIuhAAE'
from Account inner join Contact on Account.Id = Contact.AccountId
WHERE (Account.Type <> 'Prospect') and contact.mailingstate in ('ND', 'SD') and contact.OwnerID <> '00538000004tIuhAAE'

this gives me the error: Unexpected symbol 'from'

Is this type of update possible?
Thanks
-Pete

Re: Salesforce Update with Join clause

Posted: Fri 02 Feb 2018 10:54
by MaximG
Try rewriting the query as follows :

Code: Select all

UPDATE Contact
   SET Contact.OwnerID = '00538000004tIuhAAE'
  FROM [<your Linked Servere Name>]...[Contact] As Contact
         INNER JOIN [<your Linked Servere Name>]...[Account] As Account ON (Account.Id = Contact.AccountId)
  WHERE (Account.Type <> 'Prospect') And Contact.mailingstate in ('ND', 'SD') And Contact.OwnerID <> '00538000004tIuhAAE'