2017-08-21 58 views
0

我被要求發送電子郵件至我的員工有以下信息,我有:SSIS發送電子郵件任務使用變量

Excel文件(EmployeeInfo):

EmpID EmpName Rank PromoGift 
1  Peter  5  1 
2  Armand  4  2 
3  Tommy  5  5 
4  Sarah  2  4 
5  Maria  3  3 

CSV文件(促銷碼):

PromoID Validation 
1  1 
2  0 
3  1 
4  1 
5  0 

文本文件(PromoInfo)

PromoID Gift 
1  100$ Apple GC 
2  80$ Apple GC 
3  60$ Apple GC  
4  40$ Apple GC  
5  20$ Apple GC 

要求:

1. Only employees that has Validation = 1 will receive a gift. 
2. The gift is based on the PromoID (PromoGift) 
3. "Data Flow Task, Execute Sql Task, ForEach Loop & Send Mail" Task can only be used to execute the task above. 
4. In the email, I need to replace the [...] accordingly. 
5. Employee's email are neglect in this exercise. 

我會發郵件給他們以下消息:


親愛的[EmpName],

這[CurrentYear],在我們的[事件名稱]你被選爲獲得下一關的等級[Rank]的贏家。您將收到[禮物]!

您的經理[經理]的禮物!

祝賀!


我該怎麼辦(我是SSIS的新手)?

創建3個數據流任務並將每個文件加載到SQL Server表中。然後使用SQL Task完成一個Join,這樣我就可以得到誰將會收到禮物的列表,然後接下來是什麼?我應該使用什麼將這些變量插入到我的電子郵件模板中?我相信我也需要創建變量。

有什麼想法?

+0

我更喜歡在腳本任務中構建電子郵件,因爲您可以使用html。 – KeithL

回答

1

選中此項。

1.首先每個文件加載到SQL Server表 EmployeeInfoPromoCodePromoInfo

2.Open SQL Server和您需要創建一個配置文件,並使用可以訪問 配置數據庫郵件嚮導賬戶管理節點中的數據庫郵件節點的配置數據庫郵件上下文菜單。 此嚮導用於管理帳戶,配置文件和數據庫郵件全局設置

  • 查詢發送郵件

    USE msdb 
        GO 
        EXEC sp_send_dbmail @profile_name='yourprofilename', 
        @recipients='[email protected]', 
        @subject='Test message', 
        @body='This is the body of the test message. 
        Congrates Database Mail Received By you Successfully.' 
    
  • 4.

    DECLARE @email_id NVARCHAR(450)='1', @id BIGINT, @max_id BIGINT, @query NVARCHAR(1000) 
    
    SELECT @id=MIN(id), @max_id=MAX(id) FROM [EmployeeInfo ] 
    
    
    
    WHILE @id<[email protected]_id 
    BEGIN 
        SELECT @email_id=email_id ,@Gift =gift 
        FROM EmployeeInfo e join PromoInfo p on p.id = e.id 
        where ID= @id 
    
        SET @body = N''[email protected]_id+'Your Gift Is' [email protected]; 
    
        SET @body = @body 
        EXEC msdb.dbo.sp_send_dbmail 
        @profile_name = 'Profile_Name', 
        @body = @body, 
        @body_format ='HTML', 
        @recipients = @email_id, 
        @copy_recipients = '', 
        @subject = 'Subject' ; 
    
        SELECT @id=MIN(id) FROM [EmployeeInfo ] where id>@id 
    
    END 
    

    您可以使用這些示例併爲其創建SP。並在您的SSIS包中調用此SP。

    相關問題