to:zonelive(peter)
刚试了,不行,请您各我看看代码
我的触发器是这样写的:
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'Auto_Process_Statistics')
drop TRIGGER Auto_Process_Statistics
GO
CREATE TRIGGER Auto_Process_Statistics
ON Trouble_Record_Table
for Insert,update
As
Declare @Record_Date Datetime
Select @Record_Date = First_Accept_Time FROM Inserted
IF NOT EXISTS (Select * FROM Statistics_Table b WHERE @Record_Date =b.Record_Date)
Begin
Insert Into Statistics_Table (Operation_Id,Office_Name,sum) Select Operation_Type_Id,Office_Name,count(*) From Trouble_Record_Table Group by Operation_Type_Id,Office_Name ORDER BY COUNT(*) DESC
end
错了
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'Auto_Process_Statistics')
drop TRIGGER Auto_Process_Statistics
GO
CREATE TRIGGER Auto_Process_Statistics
ON Trouble_Record_Table
for Insert,update
As
--Declare @Record_Date Datetime
--Select @Record_Date = First_Accept_Time FROM Inserted
IF NOT EXISTS (Select * FROM Statistics_Table b WHERE b.Record_Date in (select First_Accept_Time FROM Inserted ))
Begin
Insert Into Statistics_Table (Operation_Id,Office_Name,sum) Select Operation_Id=Operation_Type_Id,Office_Name=Office_Name,[sum]=count(*) From Trouble_Record_Table Group by Operation_Type_Id,Office_Name ORDER BY [sum] DESC
end
你试试:
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'Auto_Process_Statistics')
drop TRIGGER Auto_Process_Statistics
GO
CREATE TRIGGER Auto_Process_Statistics
ON Trouble_Record_Table
for Insert,update
As
--Declare @Record_Date Datetime
--Select @Record_Date = First_Accept_Time FROM Inserted
IF NOT EXISTS (Select * FROM Statistics_Table b WHERE b.Record_Date in (select First_Accept_Time FROM Inserted ))
Begin
Insert Into Statistics_Table (Operation_Id,Office_Name,sum) Select Operation_Id=Operation_Type_Id,Office_Name=Office_Name,[sum]=count(*) From Trouble_Record_Table Group by Operation_Type_Id,Office_Name ORDER BY [sun] DESC
end