Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Fishwagon
Starting Member
10 Posts |
Posted - 2014-07-23 : 15:19:15
|
Hello all,I'm trying to update a column in a table using the column from another table. The column name being updated is named DocumentType and the column from the 2nd table that will supply the value is AltDocType. Not all rows in Table 1 are being updated, only a small subset. Table 2 contains all the updates needed.The first table is linked to the 2nd table by 2 columns, BatchName and BatchPg#While I can select the matching columns, I can't figure out how to modify one with the other. This query returns the matching columns I need to update:SELECT A.DocumentType, R.AltDocType FROM CorrectedBenchmarkV1 A, Update Rwhere A.Batch_Name = R.[BatchName]and A.Seq = R.BatchPg#Results:DocumentType AltDocTypeFinancial Statement Profit and Loss StatementForeclosure Statement Default CorrespondenceForeclosure Statement Default CorrespondenceForeclosure Statement Default CorrespondenceForeclosure Statement Borrower and Property InfoHere is the query I was trying to come up with to do the update:UPDATE CorrectedBenchmarkV1INNER JOIN Update RU1ON CorrectedBenchmarkV1.Batch_Name = RU1.BatchNameINNER JOIN Update RU2On CorrectedBenchmarkV1.Seq = RU2.BatchPg#SET CorrectedBenchmarkV1.DocumentType = Update.AltDocType However that is not working:Msg 156, Level 15, State 1, Line 2Incorrect syntax near the keyword 'INNER'.I thought I had to do two different joins using a different alias for each column in the UPDATE table.Any ideas?Thanks and have a great day...Rich |
|
djj55
Constraint Violating Yak Guru
352 Posts |
Posted - 2014-07-23 : 15:31:13
|
You almost got it. Try:UPDATE V1SET DocumentType = RU1.AltDocTypeFROm CorrectedBenchmarkV1 V1 INNER JOIN Update RU1ON V1.Batch_Name = RU1.BatchName AND On V1.Seq = RU1.BatchPg# djj |
|
|
Fishwagon
Starting Member
10 Posts |
Posted - 2014-07-23 : 15:38:45
|
Thank you sir, that did it....Appreciate it...Thanks and have a great day...Rich |
|
|
|
|
|