How to send the records from a table in an e-mail body using SSIS package?

前端 未结 3 1491
遥遥无期
遥遥无期 2020-12-05 03:42

I have one table called Product.

The product table have more records, Some time the table not have record.

So i want to check the product table,

<         


        
3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-05 04:03

    You can apply different approach.. Just execute a SQL Database task from SSIS to execute SP "only if you specifically want SSIS step to be executed" (or you can just create SPand schedule it in job scheduler that it). and inside the SP you can send email. in case ,if you dont know how to setup email profile refer this (https://www.codeproject.com/Articles/485124/Configuring-Database-Mail-in-SQL-Server)

    example as below -

    CREATE TABLE #Temp 
    ( 
      [Rank]  [int],
      [Player Name]  [varchar](128),
      [Ranking Points] [int],
      [Country]  [varchar](128)
    )
    
    
    INSERT INTO #Temp
    SELECT 1,'Manoj Kargeti',12390,'India'
    UNION ALL
    SELECT 2,'Vimal Kumar',7965,'Nepal'
    UNION ALL
    SELECT 3,'Pappu Djokovic',7880,'ShriLanka'
    
    
    DECLARE @xml NVARCHAR(MAX)
    DECLARE @body NVARCHAR(MAX)
    
    
    SET @xml = CAST(( SELECT [Rank] AS 'td','',[Player Name] AS 'td','',
           [Ranking Points] AS 'td','', Country AS 'td'
    FROM  #Temp ORDER BY Rank 
    FOR XML PATH('tr'), ELEMENTS ) AS NVARCHAR(MAX))
    
    
    SET @body ='

    Tennis Rankings Info

    ' SET @body = @body + @xml +'
    Rank Player Name Ranking Points Country
    ' EXEC msdb.dbo.sp_send_dbmail @profile_name = 'SQL ALERTING', -- replace with your SQL Database Mail Profile @body = @body, @body_format ='HTML', @recipients = 'bruhaspathy@hotmail.com', -- replace with your email address @subject = 'E-mail in Tabular Format' ; DROP TABLE #Temp

提交回复
热议问题