Advertisement
brunobola

Untitled

Jun 7th, 2023
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 0.72 KB | None | 0 0
  1. USE [PRITPB]
  2. GO
  3. /****** Object:  Trigger [dbo].[T_PRJ_AtulizaObra_Historico]    Script Date: 07-06-2023 15:04:35 ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8. CREATE TRIGGER [dbo].[T_PRJ_AtulizaObra_Historico] ON [dbo].[Historico]
  9. FOR INSERT, UPDATE
  10. AS
  11. -- Só deve ser executado se os campos que são necessários ao COP foram modificadados
  12. IF UPDATE(ObraID)
  13. BEGIN
  14.     SET NOCOUNT ON
  15.  
  16.     DECLARE @Cabec UNIQUEIDENTIFIER
  17.  
  18.     DECLARE XCURSOR CURSOR LOCAL FOR
  19.     SELECT id FROM INSERTED
  20.  
  21.     OPEN XCURSOR
  22.     FETCH NEXT FROM XCURSOR INTO @Cabec
  23.  
  24.     UPDATE c SET c.CDU_ObraIdAnalise=dbo.F_IDObra_Fixed_Optimized(c.ObraId)
  25.         FROM
  26.             Historico c
  27.         WHERE
  28.             c.id = @Cabec
  29.  
  30.     CLOSE XCURSOR
  31.     DEALLOCATE XCURSOR
  32.  
  33. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement