日期:2014-05-18 浏览次数:20522 次
update ProStatus set errorcount = p.errorcount from (select count(ProPK), Prjguid from proofread where status=1 group by prjguid)p where t.Prjguid = ProStatus.PrjGUID
------解决方案--------------------
上面一个p写成了t
update ProStatus set errorcount = p.errorcount from (select count(ProPK), Prjguid from proofread where status=1 group by prjguid)p where p.Prjguid = ProStatus.PrjGUID
------解决方案--------------------
update PrjGUID
set errorcount=b.errorcount
from PrjGUID a,(select count(ProPK) errorcount, Prjguid from proofread where status=1 group by prjguid
) b
where a.PrjGUID =b.PrjGUID
------解决方案--------------------
update ProStatus
set errorcount = p.errorcount
from (select count(ProPK) errorcount, Prjguid from proofread
where status=1 group by prjguid)p
where p.Prjguid = ProStatus.PrjGUID
------解决方案--------------------
update a set a.errorcount=isnull(b.errorcount,0) from ProStatus a left join (select Prjguid,count(ProPK) errorcount from proofread where status=1 group by prjguid ) b on a.PrjGUID=b.Prjguid
------解决方案--------------------
终于发现问题的根源了,是
p.Prjguid = a.PrjGUID,这句
因为
select Prjguid,count(ProPK) errorcount
from proofread where status=1
group by prjguid
里的status=1 ,导致,如果在proofread 表里没有记录,就不会有结果,并不是count(ProPK)为null,而是根本就不会有该工程的错误数查出来。
而外面又用了a.PrjGUID =b.PrjGUID,错误数不等的,根本一条也查不出来,查出来的都是相等的。