SQL server after update trigger multiple records specific record

I am trying to update the following fields;
O.USER_1 = TD.BT,
O.USER_2 = TD.MAT,
O.USER_3 = TD.WO,
O.USER_4 = TD.PN,
O.USER_5 = TD.SN,
O.UDF_LAYOUT_ID = 'OPR-HDR'

These fields are contained in the inserted record set BUT I only want to update where the I.RESOURCE_ID IN ('H-1101', 'CH-1101')

... this code updates everything row in the insert record set


        USE [db]
        GO

        SET ANSI_NULLS ON
        GO

        SET QUOTED_IDENTIFIER ON
        GO


        CREATE TRIGGER [dbo].[AFTER_INSERT_OPERATION_VR1]
        ON [dbo].[OPERATION]
        AFTER INSERT
        AS  

        BEGIN
        SET NOCOUNT ON  
        UPDATE O
        SET
        O.USER_1 = TD.BT,
        O.USER_2 = TD.MAT,
        O.USER_3 = TD.WO,
        O.USER_4 = TD.PN,
        O.USER_5 = TD.SN,
        O.UDF_LAYOUT_ID = 'OPR-HDR'

        FROM            
        INSERTED AS I INNER JOIN
                         OPERATION AS O ON
                                     I.WORKORDER_TYPE = O.WORKORDER_TYPE AND
                         I.WORKORDER_BASE_ID = O.WORKORDER_BASE_ID AND
                                     I.WORKORDER_LOT_ID = O.WORKORDER_LOT_ID AND
                         I.WORKORDER_SPLIT_ID = O.WORKORDER_SPLIT_ID AND
                         I.WORKORDER_SUB_ID = O.WORKORDER_SUB_ID
                                     
                                     INNER JOIN
                         VE7_TRIGGERDATA_OPERATION01 AS TD ON
                                     O.WORKORDER_TYPE = TD.TYPE AND
                         O.WORKORDER_BASE_ID = TD.BASE_ID AND
                         O.WORKORDER_SPLIT_ID = TD.SPLIT_ID AND
                         O.WORKORDER_LOT_ID = TD.LOT_ID AND
                         O.WORKORDER_SUB_ID = TD.SUB_ID

      WHERE        
      I.WORKORDER_BASE_ID = TD.BASE_ID AND
      I.WORKORDER_LOT_ID = TD.LOT_ID AND
      I.WORKORDER_SPLIT_ID = TD.SPLIT_ID AND
      I.WORKORDER_SUB_ID = TD.SUB_ID AND
      I.SITE_ID = TD.SITE_ID AND
      I.RESOURCE_ID IN ('H-1101', 'CH-1101')
      END

      GO
TPBasintekAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TPBasintekAuthor Commented:
I added the following and the trigger works
If (SELECT RESOURCE_ID FROM INSERTED) IN ('H-1101', 'CH-1101')

USE [SANDBOX]
GO

/****** Object:  Trigger [dbo].[AFTER_INSERT_OPERATION_VR3]    Script Date: 8/19/2015 12:03:20 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE TRIGGER [dbo].[AFTER_INSERT_OPERATION_VR3]
ON [dbo].[OPERATION]
AFTER INSERT
AS

BEGIN
SET NOCOUNT ON  
If (SELECT RESOURCE_ID FROM INSERTED) IN ('H-1101', 'CH-1101')

            begin
            UPDATE O
            SET
            O.USER_1 = TD.BT,
            O.USER_2 = TD.MAT,
            O.USER_3 = TD.WO,
            O.USER_4 = TD.PN,
            O.USER_5 = TD.SN,
            O.UDF_LAYOUT_ID = 'OPR-HDR'

            FROM            
            INSERTED AS I INNER JOIN
                                                 OPERATION AS O ON
                                                 I.WORKORDER_TYPE = O.WORKORDER_TYPE AND
                                                 I.WORKORDER_BASE_ID = O.WORKORDER_BASE_ID AND
                                                 I.WORKORDER_LOT_ID = O.WORKORDER_LOT_ID AND
                                                 I.WORKORDER_SPLIT_ID = O.WORKORDER_SPLIT_ID AND
                                                 I.WORKORDER_SUB_ID = O.WORKORDER_SUB_ID
                                     
                                                 INNER JOIN
                                                 VE7_TRIGGERDATA_OPERATION01 AS TD ON
                                                 O.WORKORDER_TYPE = TD.TYPE AND
                                                 O.WORKORDER_BASE_ID = TD.BASE_ID AND
                                                 O.WORKORDER_SPLIT_ID = TD.SPLIT_ID AND
                                                 O.WORKORDER_LOT_ID = TD.LOT_ID AND
                                                 O.WORKORDER_SUB_ID = TD.SUB_ID

            WHERE        
            I.WORKORDER_BASE_ID = TD.BASE_ID AND
            I.WORKORDER_LOT_ID = TD.LOT_ID AND
            I.WORKORDER_SPLIT_ID = TD.SPLIT_ID AND
            I.WORKORDER_SUB_ID = TD.SUB_ID AND
            I.SITE_ID = TD.SITE_ID
            END
END

GO
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.