Introduction
In this blog, you will learn how we can send an email notification through Microsoft flow and SQL Server.
Purpose
We are going to create a Microsoft flow that will get the data using an SQL stored procedure and send the result via email.
The stored procedure (If you want to send the data in HTML format).
- DECLARE @CureentDate DATETIME
- DECLARE @tableHTML NVARCHAR(MAX);
- SET @CureentDate =GETDATE();
- SET @Month=FORMAT(@CureentDate, 'MMMM')
- SET @startHtml='<html><body>'
- SET @endHtml='</body></html>'
- SELECT (FirstName+' '+LastName) AS Name,BirthDate AS BirthDate
- INTO #Sheet1
- From Employee WITH(NOLOCK)
- Set @BirthDaytable=N'<H3>Birth Date in '+@Month +'</H3>'+ '<table border="1" style="border:1px solid #77bfe4;font-family:Tahoma; font-weight:normal; font-size:12px;" cellpadding="4" cellspacing="0">' + '<tr bgcolor="#E0E0E0" style="font-family:Tahoma; font-weight:bold; font-size:12px;"><td><center>Name</center></td><td><center>BirthDate</center></td><td></td>
- </tr>' + CAST((
- SELECT
- td = K.Name
- ,''
- ,td =CONVERT(CHAR(11),K.BirthDate,113)
- ,''
- FROM #Sheet1 AS K
- ORDER BY K.BirthDate DESC
- FOR XML PATH('tr')
- ,TYPE
- --) AS NVARCHAR(MAX)) + '</table><br>Thank you</br></body></html>'
- ) AS NVARCHAR(MAX)) + '</table>'
- SET @tableHTML=@startHtml+@BirthDaytable+@endHtml
- Select @tableHTML
Join the conversation! Your thoughts help the community grow.