Reputation: 141
I am trying to update on table from another where the Primary Key for both is trans_nbr
.
My statement is posted below. All I am getting as an error is "a syntax error has occurred". The primary key is the only link between the two tables which also contain the same amount of rows.
I was able to do it before but then I found out the sequenceID on the brev_efile_user_doc_stats
table is different depending on how the XML was handled in the review process which is why there is a corrected_seq_id
column in the same table.
UPDATE
brev_efile_user_doc_stats.reviewed_event_code
, brev_efile_user_doc_stats.corrected_seq_id
SET
brev_efile_user_doc_stats.reviewed_event_code
, brev_efile_user_doc_stats.corrected_seq_id =
(SELECT
brev_efile_review.reviewed_event_code
, brev_efile_review.sequence_id
FROM
brev_efile_review
WHERE
brev_efile_review.trans_nbr = brev_efile_user_doc_stats.trans_nbr)
Upvotes: 0
Views: 48
Reputation: 1366
This is what you are looking for :
UPDATE
brev_efile_user_doc_stats
SET
brev_efile_user_doc_stats.reviewed_event_code = R.reviewed_event_code
, brev_efile_user_doc_stats.corrected_seq_id = R.sequence_id
FROM
brev_efile_user_doc_stats S
INNER JOIN brev_efile_review R
ON R.trans_nbr = S.trans_nbr
UPDATE brev_efile_user_doc_stats AS S
INNER JOIN brev_efile_review AS R ON R.trans_nbr = S.trans_nbr
SET S.reviewed_event_code = R.reviewed_event_code
, S.corrected_seq_id = R.sequence_id
Upvotes: 1