update t set 
t.famount = t1.famount
from  #temp t  
(
select t1.fid,(case when t3.fchangeno>0 then  sum(t2.FChangeBudget)
             else suM(t2.FFirstBudget) end) as FAmount 
from  p_ProjectMaster t1 ,P_ProjectList t2,#temp t3 
where t1.FID =t2.FID and t2.fchangeno=t3.fchangeno and t1.fid=t3.projectid
group by t1.fid,t3.fchangeno

t1
 where t.projectid=t1.fid 
#temp 是临时表 记录了id、变更次数和金额

解决方案 »

  1.   


    update t set  
    t.famount = t1.famount
    from (
    select t1.fid,(case when t3.fchangeno>0 then sum(t2.FChangeBudget)
      else suM(t2.FFirstBudget) end) as FAmount  
    from p_ProjectMaster t1 ,P_ProjectList t2,#temp t3  
    where t1.FID =t2.FID and t2.fchangeno=t3.fchangeno and t1.fid=t3.projectid
    group by t1.fid,t3.fchangeno
    )  t1 
    where t.projectid=t1.fid  --try
      

  2.   

     #temp t(
    select
    这里加个逗号