2012-10-26 97 views
0

我需要您的支持here.I想要更改爲一個更新聲明,我想要從PersonDeatl與Birthage更新E.Age的所有空值。下面的腳本只是選擇.Table Employee和and PersonDeatl沒有鑰匙加入他們也沒有與EmpRet.Thanks球員從選擇更新腳本

select distinct * from ((Select  
      E.EmployeeId,E.Address,E.City,E.Zip,E.State,E.Age 
     from Employee E join 
      EmpRet R 
      on E.EmployeeId=R.EmployeeId 
     where R.Dscription='Age not Qualify' and E.Age is null)Ag inner join 
     (select address,city,zip,state,BirthAge from PersonDeatl)Pd 

      on ag.Address=Pd.Address and ag.City=Pd.City and ag.zip=Pd.Zip) 

回答

0

你可以試試這個。

With EmpCTE (Age, BirthAge) as (
    SELECT E.Age, P.BirthAge 
    FROM Employee E 
    JOIN PersonDeatl P 
    ON E.Address = P.Address 
    AND E.City=P.City 
    AND E.Zip=P.Zip 
    Where E.Age IS NULL 
) 

UPDATE EmpCTE 
SET Age = BirthAge