--请先做好数据备份! --1.请在当前月未结帐前执行如下语句: delete from ia_summary where imonth>(select max(iperiod)+1 from gl_mend where bflag_ia=1) --2.再用以下语句删除存货总帐重复记录即可 declare @imonth as int set @imonth=0 while @imonth1) ia on ia_summary.cwhcode=ia.cwhcode and ia_summary.cinvcode=ia.cinvcode and ia_summary.imonth=ia.imonth where autoid not in(select min(autoid) from ia_summary where imonth=@imonth group by cwhcode,cinvcode,imonth having count(*)>1) and ia_summary.imonth=@imonth set @imonth=@imonth+1 end