Need help with the Merge statement

前端 未结 3 1564
轻奢々
轻奢々 2021-01-13 08:11

I want to update a table called Sorels_ext from a table called Sorels. The link between them is the fkey_id of Sorels_ext equals the identity_column of the Sorels table. Thi

相关标签:
3条回答
  • 2021-01-13 08:38
    INSERT (SORe.fkey_id, SORe.Color) 
    

    should read:

    INSERT (fkey_id, Color) 
    

    Columns in the insert list can only refer to the target table. The parser doesn't expect to see a table alias there, and doesn't know how to resolve it.

    If it sees "column1", it knows it belongs to the target table. It sees "table1.column1", it doesn't know what "table1" means, since "table1" as a token is out of scope.

    0 讨论(0)
  • 2021-01-13 08:48

    Try taking out the "AS" in your ") AS SOR"

    0 讨论(0)
  • 2021-01-13 08:53

    I believe you have to alias your your source data like so:

    USING (select SOR.identity_column, 
       CASE  WHEN left(SOR.FPARTNO, 2) = 'BL' 
       THEN 'Blue'        
       WHEN left(SOR.FPARTNO, 2) = 'RD' 
       THEN 'Red'        
       ELSE 'White'      
       END from Sorels AS SOR) **AS SOR** ON  (SORe.fkey_id = SOR.identity_column)
    
    0 讨论(0)
提交回复
热议问题