SQLTeam.com | Weblogs | Forums

How to pull data from one table to another table based on certain condition


I've two tables. Table one is named RAW and table two is named REPORT. Please see below screenshots. Both the tables are in Relationship with Column name REQUESTID, however the only difference is - REPORT.REQUESTID is DISTINCT of RAW.REQUESTID and rest of the fields or REPORT table are blank.

I'm looking for Query to fill data in REPORT table but my conditions are

To INSERT Data in *NEW* Column


When above condition is true, REPORT.NEW should have the value from RAW.LASTUPDATEON. Result will look like below screenshot which I've manually filled.

Any help will be much appreciated.

UPDATE ReportTable
SET NEW = RawTable.LastUpDateOn 
FROM Report ReportTable
INNER JOIN Raw RawTable ON ReportTable.RequestID = RawTableRequestID AND RawTable.LastStatus = 'NEW";

Notice this just answers your question. It does not consider other problems.