2012-03-23 74 views
1

我有nol_art和#tmpIzm我想從表#tmpIzm值nol_art更新,如果它不是空兩個表更新值表,否則值保持不變
我寫的代碼,但是有是一些錯誤,所以不工作:如何從另一個表

update nol_art 
    set 
     CENA_IZM=if(xd.IZM IS NULL,' ',xd.IZM) 
    from 
     #tmpIzm xd 
     join nol_art a on a.ART_ID=xd.ID_ART 
    where 
     a.ART_ID=xd.ID_ART 

回答

3

試試這個:

update nol_art 
    set 
     CENA_IZM=coalesce(xd.IZM, CENA_IZM) 
    from 
     #tmpIzm xd 
     join nol_art a on a.ART_ID=xd.ID_ART 
    where 
     a.ART_ID=xd.ID_ART 
+0

謝謝,這工作正常。 – Brezhnews 2012-03-23 09:26:26

1

我做到了在DB2

UPDATE 
     document 
    SET 
     department =  
      (SELECT departmentId 
       FROM 
       department 
      WHERE 
       document.base_child = document.base_child AND 
       document.folder_child = document.folder_child) 
    WHERE 
     EXISTS 
     (SELECT * FROM department 
        WHERE department.base_child = department.base_child 
        AND department.folder_child = department.folder_child); 

希望能幫到