SQL update from one Table to another based on a ID match IN db2

后端 未结 6 970
遥遥无期
遥遥无期 2020-11-27 08:28

The Query below is suited in SQL sErver. But in DB2 it does not give results:

Error is  SQLCODE = -199, ERROR:  ILLEGAL USE OF KEYWORD FROM. 
6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-27 08:48

    If you want to use UPDATE rather than MERGE, you want to process only the matching records where the value will change.

    UPDATE Sales_Import SI
      SET SI.AccountNumber = 
            (SELECT RAN.AccountNumber
               FROM RetrieveAccountNumber RAN
               WHERE SI.LeadID = RAN.LeadID
               FETCH FIRST ROW ONLY
            )
      WHERE SI.LeadID IN
            (SELECT S2.LeadID
               FROM Sales_Import S2
               JOIN RetrieveAccountNumber R2
                 ON S2.LeadID = R2.LeadID
               WHERE S2.AccountNumber <> R2.RetrieveAccountNumber 
            )
    

提交回复
热议问题