set @BDate=getdate() --下面这句速度很慢,但去掉WorkReg表的触发器则正常 if not exists(select iId from WorkReg where PlanId=@PlanId and tiId=@tiId and StepId=@StepId and StationId=@Station1 and iEmplId=@iEmp1 and StationGp=@StationGp1 and RegDate=@Date1 and TmpStepAssId=@TmpStepAssId) begin set @EDate=getdate() insert into aCost(StepNo,begindate,enddate,costm) values (5,@BDate,@EDate,datediff(ms,@BDate,@EDate)) set @BDate=@EDate --插入数据至WorkReg表 select @iId=IsNull(max(iId)+1,1) from WorkReg insert into WorkReg(iId, PlanId, tiId, OrganId, ProdId, StepId, StationId, StationGp,iEmplId, Num, RegDate,PlanProdId,EmpId, WorkPrice,QuoPercent,AllQuoPercent,WorkTime,TmpStepAssId,IsTempTask, StepName,TechOrderId,StationName,SemiName,WorkNum, PlanNo,OrganCode,SalaKind,IsReversePoint,cEmpCode,cEmplN, SpecCode,DetailCode,ProdCode,ProdName,Factor,AlreadyReverse) values(@iId,@PlanId,@tiId,@OrganId,@ProdId,@StepId,@Station1,@StationGp1, @iEmp1,@Num1,@Date1,@PlanProdId,@IID1,@WorkPrice,@QuoPercent1,@AQuoPcent1, @WorkTime,@TmpStepAssId,@IsTempTask,@StepName,@TechOrderId,@StationN1,@SemiName,@WorkNum, @PlanNo,@OrganCode,@SalaKind,@IsReversePoint,@cEmpCode1,@cEmplN1,@SpecCode, @DetailCode,@ProdCode,@DetailName,@Factor,@AlreadyReverse) end else update WorkReg set Num=@Num1,QuoPercent=@QuoPercent1,AllQuoPercent=@AQuoPcent1,Factor=@Factor where PlanId=@PlanId and tiId=@tiId and StepId=@StepId and StationId=@Station1 and iEmplId=@iEmp1 and StationGp=@StationGp1 and RegDate=@Date1 and TmpStepAssId=@TmpStepAssId 贴出来大家看下,实在想不明白啊!