select * from t_itemdetail exec sp_cleanitemdetailv GO update a set a.fdetailcount=b.Fcount from t_itemdetail a join (select Fdetailid,count(*) as Fcount from t_itemdetailv where fitemid=-1 group by Fdetailid) b on a.fdetailid=b.fdetailid where a.fdetailcount<>b.Fcount
以上语句只能修正核算项目关系,如果丢失F列,还需要进行F列的补回,需要根据实际情况,供参考,如:修改F3001和3001为实际的数据 If Not Exists(Select c.Name from syscolumns c,sysobjects o where c.Id=o.Id and c.name='F3001' and o.name='t_ItemDetail') Begin Alter Table t_ItemDetail Add F3001 int not null default(0) Create Index ix_ItemDetail_3001 On t_ItemDetail(F3001) END
|