Advertisement
Guest User

Untitled

a guest
Sep 25th, 2014
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 2.53 KB | None | 0 0
  1. USE [eForms]
  2. GO
  3. /****** Object:  Trigger [dbo].[RoutePlan_AuditTrigger]    Script Date: 9/25/2014 12:36:48 PM ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8.  
  9. ALTER TRIGGER [dbo].[RoutePlan_AuditTrigger] ON [dbo].[RoutePlan]
  10.     FOR INSERT, UPDATE, DELETE
  11. AS
  12.     BEGIN
  13.    
  14.         DECLARE @s_RowAction VARCHAR(16)
  15.         DECLARE @i_DeleteCount INT
  16.         DECLARE @i_InsertCount INT
  17.    
  18.         SELECT  @i_DeleteCount = COUNT(*)
  19.         FROM    DELETED
  20.         SELECT  @i_InsertCount = COUNT(*)
  21.         FROM    INSERTED
  22.    
  23.         IF @i_DeleteCount = 0
  24.             AND @i_InsertCount > 0
  25.             SET @s_RowAction = 'INSERT'
  26.         IF @i_DeleteCount > 0
  27.             AND @i_InsertCount > 0
  28.             SET @s_RowAction = 'UPDATE'
  29.         IF @i_DeleteCount > 0
  30.             AND @i_InsertCount = 0
  31.             SET @s_RowAction = 'DELETE'
  32.  
  33.        
  34.         IF @s_RowAction = 'INSERT'
  35.             OR @s_RowAction = 'UPDATE'
  36.             INSERT  INTO RoutePlanAudit(
  37.                     RoutePlanId ,
  38.                     FormId ,
  39.                     UserId ,
  40.                     Rank ,
  41.                     RoutePlanStatusId ,
  42.                     StatusDate ,
  43.                     Notes ,
  44.                     IsStrict ,
  45.                     RoutePlanResponsibilityId ,
  46.                     IsPostApproval ,
  47.                     ProcessedByUserId ,
  48.                     Deleted ,
  49.                     RowAction ,
  50.                     ModifiedById ,
  51.                     ModifiedDate
  52.                 )
  53.                     SELECT  RoutePlanId ,
  54.                             FormId ,
  55.                             UserId ,
  56.                             Rank ,
  57.                             RoutePlanStatusId ,
  58.                             StatusDate ,
  59.                             Notes ,
  60.                             IsStrict ,
  61.                             RoutePlanResponsibilityId ,
  62.                             IsPostApproval ,
  63.                             ProcessedByUserId ,
  64.                             Deleted ,
  65.                             @s_RowAction ,
  66.                             ISNULL(ModifiedById,CreatedById) ,
  67.                             GETDATE()
  68.                     FROM    INSERTED
  69.                        
  70.         IF @s_RowAction = 'DELETE'
  71.             INSERT  INTO RoutePlanAudit(
  72.                     RoutePlanId ,
  73.                     FormId ,
  74.                     UserId ,
  75.                     Rank ,
  76.                     RoutePlanStatusId ,
  77.                     StatusDate ,
  78.                     Notes ,
  79.                     IsStrict ,
  80.                     RoutePlanResponsibilityId ,
  81.                     IsPostApproval ,
  82.                     ProcessedByUserId ,
  83.                     Deleted ,
  84.                     RowAction ,
  85.                     ModifiedById ,
  86.                     ModifiedDate
  87.                 )
  88.                     SELECT  RoutePlanId ,
  89.                             FormId ,
  90.                             UserId ,
  91.                             Rank ,
  92.                             RoutePlanStatusId ,
  93.                             StatusDate ,
  94.                             Notes ,
  95.                             IsStrict ,
  96.                             RoutePlanResponsibilityId ,
  97.                             IsPostApproval ,
  98.                             ProcessedByUserId ,
  99.                             Deleted ,
  100.                             @s_RowAction ,
  101.                             ISNULL(ModifiedById,CreatedById) ,
  102.                             GETDATE()
  103.                     FROM    DELETED
  104.                    
  105.     END
  106.  
  107.     SET ANSI_NULLS ON
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement