Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Update record if master table record exist Expand / Collapse
Author
Message
Posted Wednesday, June 19, 2013 7:03 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, September 4, 2014 7:39 AM
Points: 91, Visits: 214
I want to update the PO table with the BuyerName if there is a Buyer record exist.
In below example , it should update Buyer field in PO Table with Roger James as there is a record exist for code RAJ.
It should not update PO Table for james Kidlo as there is no Buyer code exist.

PO Table
PO# Buyer
----- ------------
PO001 RAJ
PO002 James Kidlo

Buyer Table
Buyer Name
------ --------------
RAJ Roger James
PRK Paul Kisslebeck
Post #1465143
Posted Wednesday, June 19, 2013 7:43 AM


SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Saturday, September 13, 2014 5:47 AM
Points: 99, Visits: 2,199
You're going to have a problem as it looks like you want to update a join key on the PO Table

Why do you want to update the PO Table? Which column do you want to update?
Post #1465172
Posted Wednesday, June 19, 2013 7:59 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Monday, June 23, 2014 8:04 AM
Points: 83, Visits: 174
Consider normalizing these tables in future.
For now, Check if this works:

Update POTable
set Buyer = PO.Name
FROM POTable PO inner join BuyerTable BT
ON PO.Buyer = BT.Buyer
Post #1465183
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse