How to Update a Table Using “OR” Joins

Hello:

In tables called IV00102 and RM00102, for a certain set of customers with Address IDs, I changed the Site ID (i.e. location) to 2.  Now, I need to--in GP's Sales Order Processing module's history--change the Site ID for the same customers and Address IDs to 2.  That set of customers is in a table called "CUSTOMERS4SITE2".
 
The problem that I'm having with the T-SQL query update statement is that--for the SOP30200 table--I don't know if the Address IDs in CUSTOMERS4SITE2 are a "ship to ID" (SOP30200.PRSTADCD) or "bill to" ID (SOP30200.PRBTADCD).  
 
Below is the update statement that I have.  Will this work?  
 
TBSupport
 
 
UPDATE SOP30200 SET SOP30200.LOCNCODE = '2'
from SOP30200
INNER JOIN CUSTOMERS4SITE2 ON (SOP30200.CUSTNMBR = CUSTOMERS4SITE2.CustomerNumber and SOP30200.PRSTADCD = CUSTOMERS4SITE2.AddressCode)
OR
(SOP30200.CUSTNMBR = CUSTOMERS4SITE2.CustomerNumber and SOP30200.PRBTADCD = CUSTOMERS4SITE2.AddressCode)
where (CUSTOMERS4SITE2.CustomerNumber = SOP30200.CUSTNMBR and SOP30200.PRSTADCD = CUSTOMERS4SITE2.AddressCode)
OR
(CUSTOMERS4SITE2.CustomerNumber = SOP30200.CUSTNMBR and SOP30200.PRBTADCD = CUSTOMERS4SITE2.AddressCode)
LVL 1
TBSupportAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

LowfatspreadCommented:
please explain the significance of a ship to or bill to address....

don't you need location codes for each address type?

in fact please explain what you are attempting to do... what is the significance of a site for a customer? can customers not be present at multiple sites?

can a bill to address have a different site from a ship to address?

consider using exists

e.g.
update yourtable
  set location_no=2
where exists (select custno 
   from site2customer as x
    where yourtable.customer=x.custno
      and (yourtable.billtoaddr=x.addr
        or yourtable.shiptoaddr = x.addr)
    )

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.