在SSRS订阅中用新电子邮件替换旧电子邮件地址

时间:2018-08-08 17:42:32

标签: reporting-services

该公司决定更改其域名,并且不再接受旧的电子邮件地址。需要更新所有这些订阅中的电子邮件地址,而无需进入每个订阅并进行更新。

1 个答案:

答案 0 :(得分:0)

USE abc 

DECLARE @list TABLE 
  ( 
     id              INTEGER IDENTITY(1, 1) PRIMARY KEY, 
     oldemailaddress VARCHAR(100), 
     newemailaddress VARCHAR(100) 
  ) 

INSERT INTO @list 
            (oldemailaddress, 
             newemailaddress) 
SELECT [global address], 
       [abc-address] 
FROM   [dbo].[abc-data final] 

--select * from @list 
DECLARE @OldEmailAddress VARCHAR(100), 
        @NewEmailAddress VARCHAR(100), 
        @totalRecords    INT, 
        @I               INT, 
        @SubscriptionID  UNIQUEIDENTIFIER 
DECLARE email_cursor CURSOR FOR 
  SELECT oldemailaddress, 
         newemailaddress 
  FROM   @list 

OPEN email_cursor 

FETCH next FROM email_cursor INTO @OldEmailAddress, @NewEmailAddress 

WHILE @@FETCH_STATUS = 0 
  BEGIN 
      BEGIN TRANSACTION 

      UPDATE abc.dbo.subscription_email_test 
      SET    extensionsettings = CONVERT(NTEXT, Replace( 
                                        CONVERT(VARCHAR(max), extensionsettings) 
                                                , 
                                                    @OldEmailAddress, 
                                                       @NewEmailAddress)) 
      FROM   abc.dbo.subscription_email_test 
      WHERE  CONVERT(VARCHAR(max), extensionsettings) LIKE 
                    '%' 
                                                           + CONVERT(VARCHAR(100 
                    ), 
                    @OldEmailAddress 
                    ) 
                                                           + '%' 

      --rollback transaction 
      COMMIT TRANSACTION 

      PRINT 'Old: ' + @OldEmailAddress + ' New: ' 
            + @NewEmailAddress + 'SubscriptionID: ' 
            + Isnull(CONVERT(NVARCHAR(max), @SubscriptionID), 'NOT FOUND') 

      FETCH next FROM email_cursor INTO @OldEmailAddress, @NewEmailAddress 
  END 

CLOSE email_cursor 

USE abc 

DECLARE @list TABLE 
  ( 
     id              INTEGER IDENTITY(1, 1) PRIMARY KEY, 
     oldemailaddress VARCHAR(100), 
     newemailaddress VARCHAR(100) 
  ) 

INSERT INTO @list 
            (oldemailaddress, 
             newemailaddress) 
SELECT [global address], 
       [abc-address] 
FROM   [dbo].[abc-data final] 

--select * from @list 
DECLARE @OldEmailAddress VARCHAR(100), 
        @NewEmailAddress VARCHAR(100), 
        @totalRecords    INT, 
        @I               INT, 
        @SubscriptionID  UNIQUEIDENTIFIER 
DECLARE email_cursor CURSOR FOR 
  SELECT oldemailaddress, 
         newemailaddress 
  FROM   @list 

OPEN email_cursor 

FETCH next FROM email_cursor INTO @OldEmailAddress, @NewEmailAddress 

WHILE @@FETCH_STATUS = 0 
  BEGIN 
      BEGIN TRANSACTION 

      UPDATE abc.dbo.subscription_email_test 
      SET    extensionsettings = CONVERT(NTEXT, Replace( 
                                        CONVERT(VARCHAR(max), extensionsettings) 
                                                , 
                                                    @OldEmailAddress, 
                                                       @NewEmailAddress)) 
      FROM   abc.dbo.subscription_email_test 
      WHERE  CONVERT(VARCHAR(max), extensionsettings) LIKE 
                    '%' 
                                                           + CONVERT(VARCHAR(100 
                    ), 
                    @OldEmailAddress 
                    ) 
                                                           + '%' 
      COMMIT TRANSACTION 

      PRINT 'Old: ' + @OldEmailAddress + ' New: ' 
            + @NewEmailAddress + 'SubscriptionID: ' 
            + Isnull(CONVERT(NVARCHAR(max), @SubscriptionID), 'NOT FOUND') 

      FETCH next FROM email_cursor INTO @OldEmailAddress, @NewEmailAddress 
  END 

CLOSE email_cursor 
DEALLOCATE email_cursor ;


----------