再一个是有存在要修改好几个字段不要都这样写吧
fnetweight=fnetweight+(select fnetweight from 
     inserted where bmonth.fbreedid=inserted.fbreedid
     and bmonth.fprounitid=inserted.fprounitid )
     ftax=ftax+(select  ftax from inserted where bmonth.fbrredid=
inseerte.fbreedid and bmonth.fprounitid=binserted.fprounitid) adn

解决方案 »

  1.   

    楼主思路有问题,这个就是一个判断是否存在的问题,关键是看你月报表怎么设计的
    月报表里面应该有月份指示才对,然后插入的时候判断插入的月份在报表里面是否有,有就+1,没有就insert
      

  2.   

    对呀,我的月报表里有年份,月份和供料单位及品名,有的话,车数就加一,重量加上过磅的重量
    楼主说对了,但是你的语句有点问题,没有必要那么烦琐,还有就是你的明细表里面竟然没有日期吗?要靠插入日期来判断该记录的日期?这样设计的太不合理了吧?你以后怎么查这条记录的称的日期?
    按楼主的写法可以这么优化:
     if exists
         (select 1 from bmonth,inserted
         where bmonth.fbreedid=inserted.fbreedid 
         and bmonth.fprounitid=inserted.fprounitid 
         and bmonth.fmonth=month(getdate()) 
         and fyear=year(getdate())
         )
    ...
      

  3.   

    --那就这么写吧,更加合理一点.后面更新和插入的语句里面的日期应该也用这个字段比较好.否则你计算
    --的日期(getdate())未必是你真正的业务日期
    --当然如果你业务需求就是,以计算日期为准的化就另当别论.
     if exists
         (select 1 from bmonth,inserted
         where bmonth.fbreedid=inserted.fbreedid 
         and bmonth.fprounitid=inserted.fprounitid 
         and bmonth.fmonth=month(inserted.datecolumn)
         and fyear=year(inserted.datecolumn)
         )