再一个是有存在要修改好几个字段不要都这样写吧
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
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,没有就insert
楼主说对了,但是你的语句有点问题,没有必要那么烦琐,还有就是你的明细表里面竟然没有日期吗?要靠插入日期来判断该记录的日期?这样设计的太不合理了吧?你以后怎么查这条记录的称的日期?
按楼主的写法可以这么优化:
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())
)
...
--的日期(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)
)