Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Update record if master table record exist


Update record if master table record exist

Author
Message
skb 44459
skb 44459
SSC-Enthusiastic
SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)

Group: General Forum Members
Points: 115 Visits: 267
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
Cowboy DBA
Cowboy DBA
SSC Journeyman
SSC Journeyman (99 reputation)SSC Journeyman (99 reputation)SSC Journeyman (99 reputation)SSC Journeyman (99 reputation)SSC Journeyman (99 reputation)SSC Journeyman (99 reputation)SSC Journeyman (99 reputation)SSC Journeyman (99 reputation)

Group: General Forum Members
Points: 99 Visits: 2255
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?
mayurkb
mayurkb
SSC Journeyman
SSC Journeyman (88 reputation)SSC Journeyman (88 reputation)SSC Journeyman (88 reputation)SSC Journeyman (88 reputation)SSC Journeyman (88 reputation)SSC Journeyman (88 reputation)SSC Journeyman (88 reputation)SSC Journeyman (88 reputation)

Group: General Forum Members
Points: 88 Visits: 238
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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search