日期:2014-05-19  浏览次数:20429 次

请指正下列触发器中的错误
CREATE   TRIGGER   Ck_BcpIn_Dtl_ino     ON   dbo.Ck_BcpIn_Dtl  
FOR   insert
AS
Begin
Set   NoCount   On
declare   @Container_Code   as   Nvarchar(10)
declare   @Ymonth   as   Nvarchar(6)
declare   @type   as   Nvarchar(10)
declare   @store   as   Nvarchar(10)
declare   @cp_model     As   NvarChar(18)
declare   @cp_name     As   NvarChar(30)
declare   @cp_size     As   NvarChar(10)
declare   @cp_packing     As   NvarChar(10)
declare   @cp_grade     As   NvarChar(10)
declare   @cp_sb     As   NvarChar(10)
declare   @cp_stplace     As   NvarChar(10)
declare   @cp_pc   As   NvarChar(10)
declare   @In_Num     As   Numeric(9,0)

DECLARE   Temp_Table   CURSOR   FOR
Select     Container_Code,Ymonth,type,Store,Cp_model,cp_name,Cp_size,cp_packing,
                      cp_grade,cp_sb,cp_stplace,cp_pc,in_num       from   inserted
OPEN   Temp_Table
FETCH   NEXT   FROM   Temp_Table
INTO   @Container_Code,@Ymonth,   @type,@Store,@cp_model,@cp_name,@cp_size,@cp_packing,@cp_grade,@cp_sb,@cp_stplace,@cp_pc,   @In_Num
WHILE   @@FETCH_STATUS   =   0
BEGIN
update   Bcp_Xs_StDepInfoOut   set     Sdinfo_In=   Sdinfo_In+(@In_Num*@cp_packing)     Where    
                  Container_Code=@Container_Code       and     Ymonth=@Ymonth       And     type=@type     and   Store=@Store  
                  and     cp_model=@cp_model     and     cp_name=@cp_name     and   cp_size=@cp_size   and   cp_packing=@cp_packing  
                  and   cp_grade=@cp_grade     and     cp_sb=@cp_sb   and     cp_stplace=@cp_stplace     and     cp_pc=@cp_pc
  if   @@rowcount=0
        Begin
        Insert   into   Bcp_Xs_StDepInfoOut(container_code,ymonth,type,   store,   cp_model,   cp_name,cp_size,cp_packing,cp_grade,cp_sb,cp_stplace,cp_pc,sdinfo_in)
        Values   (   @Container_Code,@Ymonth,   @type,@Store,@cp_model,@cp_name,@cp_size,@cp_packing,@cp_grade,@cp_sb,@cp_stplace,@cp_pc,   @in_Num)
        End  
FETCH   NEXT   FROM   Temp_Table
INTO   @Container_Code,@Ymonth,   @type,@Store,@cp_model,@cp_name,@cp_size,@cp_packing,@cp_grade,@cp_sb,@cp_stplace,@cp_pc,   @in_Num
END

CLOSE   Temp_Table
DEALLOCATE   Temp_Table
Set   NoCount   Off




------解决方案--------------------
CREATE TRIGGER Ck_BcpIn_Dtl_ino ON dbo.Ck_BcpIn_Dtl
FOR insert
AS
Begin
--Set NoCount On
declare @Container_Code as Nvarchar(10)
declare @Ymonth as Nvarchar(6)
declare @type as Nvarchar(10)
declare @store as Nvarchar(10)
declare @cp_model As NvarChar(18)
declare @cp_name As NvarChar(30)
decla