1

I know how to do this when the ID columns match, I do not know how to do it when they do not. I need to update the value in one row of a table in one database with the value of a column from another database. They do not have the same ID's.

UPDATE DevDatabase
SET DevDatabase.ReportData = TESTDatabase.ReportData
Where DevDatabase.SavedReportId = '0B6D01B7-D52E-4799-B809-DA375449AF30'
FROM TESTDatabase.[SavedReport] TEST
where TEST.SavedReportId =   '02F62AD5-7DA2-414D-873E-1ED6B922DB53'

I hope the code above though incorrect demonstrates what I need.

2 Answers 2

4

Using subquery:

UPDATE DevDatabase.SavedReport
SET ReportData = (SELECT ReportData 
                 FROM TESTDatabase.[SavedReport] TEST 
                 WHERE TEST.SavedReportId = '02F62AD5-7DA2-414D-873E-1ED6B922DB53')
Where SavedReportId = '0B6D01B7-D52E-4799-B809-DA375449AF30'
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much!
1

You can also use the update/join syntax, as you originally intended:

  • there should be only one WHERE clause in the query

  • the update clause should refer to a table (or alias) defined in the from clause

Query:

UPDATE d
SET ReportData = t.ReportData
FROM DevDatabase.SavedReport d
JOIN TESTDatabase.[SavedReport] t 
    ON t.SavedReportId = '02F62AD5-7DA2-414D-873E-1ED6B922DB53'
WHERE d.SavedReportId = '0B6D01B7-D52E-4799-B809-DA375449AF30'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.