每次触发触发器时都会发生错误

时间:2016-05-14 12:03:01

标签: sql sql-server-2012

我收到此错误:

  

[Microsoft] [ODBC SQL Server驱动程序] [SQL Server] 1
  (用于ODBC驱动程序的Microsoft OLE DB提供程序)

任何时候触发此触发器:

ALTER TRIGGER [dbo].[trgDR] 
   ON  [dbo].[Deceased Register]
   AFTER  INSERT 
AS 
BEGIN

    SET NOCOUNT ON;
declare @parishid int, @monthid int, @yearid int,@total float,@gtotal float
    select @parishid =i.Parish_id from inserted i;
    select @monthid=i.Month_id from inserted i;
    select @yearid=i.year_id from inserted i;    

    select @total=COUNT(*) from [Deceased Register] 
        where Parish_id=@parishid and Year_id=@yearid and 
        Month_id=@monthid               
        print @total
        select @gtotal=COUNT(*) from [Deceased Register] 
        where Parish_id=@parishid and Year_id=@yearid 
        print @total

        if not exists(select parish_id from ParishStatistics 
        where parish_id=@parishid and Year_id=@yearid and month_id=@monthid)
        begin
            insert into ParishStatistics (Parish_id,Year_id,month_id,Deceased)
            values (@parishid,@yearid,@monthid,@total)

        end

        else
        begin
            update ParishStatistics 
            set Deceased=@total 
            where Parish_id=@parishid and Year_id=@yearid  and month_id=@monthid
        end

        update ParishStatistics 
        set AnnualDeceased=@gtotal
        where Parish_id=@parishid and Year_id=@yearid

END

0 个答案:

没有答案