Creating Trigger Sql Server

0

I am creating a trigger to create a copy of the changed data in the table. But you have an error.

USE [BANCO1]
GO
/****** Object:  Trigger [dbo].[BANCO1]    Script Date: 08/07/2015 14:13:34 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER [dbo].[BANCO1]
  ON [dbo].[TABLE1]
  AFTER  UPDATE
AS


  BEGIN
    DECLARE
    @NOSSONRO   VARCHAR(15) 
    SELECT @NOSSONRO = E1_NUMBCO FROM UPDATED
    SET NOCOUNT ON;

    UPDATE TABLE1 SET E1_NOSNRO = @NOSSONRO  WHERE  E1_NOSNRO='' AND E1_NUMBCO=@NOSSONRO


  END
    
asked by anonymous 08.07.2015 / 19:15

1 answer

0

Between the Begin and End of your trigger use the following code:

SET NOCOUNT ON;

DECLARE @NOSSONRO AS VARCHAR(15);

/*Código abaixo obtém o novo E1_NUMBCO, ou seja o valor atualizado. 
Se você quiser pegar o valor antigo do E1_NUMBCO utilize DELETED no lugar do INSERTED*/

SELECT @NOSSONRO = E1_NUMBCO FROM INSERTED;

UPDATE TABLE1 SET E1_NOSNRO = @NOSSONRO  WHERE  E1_NOSNRO='' AND E1_NUMBCO=@NOSSONRO

In Sql Server we do not have the updated. The updated is treated as an exclusion followed by an inclusion.

    
08.07.2015 / 20:59