spBulkUpdate_EmailJob_Recipient_EmailJobID

Parameters

Parameter Parameter Type Mode Description
@EmailJobID int IN
@XML ntext IN

Definition

Copy


            CREATE PROCEDURE [dbo].[spBulkUpdate_EmailJob_Recipient_EmailJobID]
                @EmailJobID int,
                @XML ntext
            AS
            BEGIN

                Declare @EmailJob_RecipientIDs Table (ID int)
                DECLARE @idoc int

                -- Read the IDs from the XML into a table
                EXEC sp_xml_preparedocument @idoc OUTPUT, @XML
                INSERT INTO @EmailJob_RecipientIDs
                SELECT *
                FROM OPENXML (@idoc, '/emailJobRecipientCollection/emailJobRecipient', 2)
                WITH ([ID] int '@ID')
                EXEC sp_xml_removedocument @idoc

                -- Update the EmailJob_Recipients to point to the new EmailJobID
                Update EmailJob_Recipient
                    Set EmailJobID = @EmailJobID
                FROM EmailJob_Recipient ejr
                Join @EmailJob_RecipientIDs ej
                    ON  ejr.ID = ej.ID

            END