日期:2014-05-17  浏览次数:20438 次

一个入门级的触发器问题求助
SQL code
一个简单的触发器,在表whir$t3036插入一条记录后,从插入记录选取若干,组成一跳新纪录插入到另一张表whir$3036$old中。。。。
 
出现问题:此触发器使用后,原表whir$t3036无法插入记录了!!
 
注:表whir$t3036是合同单,用户在前台填单后自动插入记录
 
第一次用触发器,哪位知道咋回事,感激不尽!
 
USE [OA]
 GO
 /****** 对象:  Trigger [ezoffice].[whir_t3036_ToOld]    脚本日期: 07/27/2012 11:35:49 ******/
 SET ANSI_NULLS ON
 GO
 SET QUOTED_IDENTIFIER ON
 GO
 -- =============================================
 -- Author:  <Author,,Name>
 -- Create date: <Create Date,,>
 -- Description: <Description,,>
 -- =============================================
 ALTER TRIGGER [ezoffice].[whir_t3036_ToOld]  
    ON  [ezoffice].[whir$t3036] 
   AFTER INSERT
 AS 
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
--SET NOCOUNT ON;
     -- Insert statements for trigger here
 declare @htbh varchar(40)
 set @htbh = (select whir$t3036_f4149 from INSERTED)
     declare @khmc varchar(40)
 set @khmc = (select whir$t3036_f3357 from INSERTED)
 declare @htje float
 set @htje = (select whir$t3036_f3656 from INSERTED)
     declare @department float
 set @department = (select whir$t3036_f3355 from INSERTED)
   declare @ren float
 set @ren = (select whir$t3036_f3356 from INSERTED)
 insert into ezoffice.whir$3036$old  (htbh,khmc,htje,department,ren)
   values(@htbh ,@khmc,@htje,@department,@ren )
 END 





------解决方案--------------------
SQL code
USE [OA]
 GO
 /****** 对象:  Trigger [ezoffice].[whir_t3036_ToOld]    脚本日期: 07/27/2012 11:35:49 ******/
 SET ANSI_NULLS ON
 GO
 SET QUOTED_IDENTIFIER ON
 GO
 -- =============================================
 -- Author:  <Author,,Name>
 -- Create date: <Create Date,,>
 -- Description: <Description,,>
 -- =============================================
 ALTER TRIGGER [ezoffice].[whir_t3036_ToOld]  
    ON  [ezoffice].[whir$t3036] 
INSERT
 AS 
BEGIN

declare @htbh varchar(40),@khmc varchar(40),@htje float,@department float,@ren float

 select 
@htbh = whir$t3036_f4149,
@khmc = whir$t3036_f3357, 
@htje = whir$t3036_f3656,
@department = whir$t3036_f3355 , 
@ren = whir$t3036_f3356     
from INSERTED 
insert into ezoffice.whir$3036$old  (htbh,khmc,htje,department,ren)
values(@htbh ,@khmc,@htje,@department,@ren )
 END

------解决方案--------------------
@1楼
换成单个查询就ok?