Sending the result of an SQL query in HTML format via Logic App
It is a very simple requirement, you need a result of querying the database, that is, a direct output from a table or a result returned from the procedure needs to be sent by email. This email can be a picture of the moment of execution, some daily verification of a processing or simply a notification of something that shouldn’t have happened. And to facilitate understanding we will send the result formatted in HTML.
There are countless effective ways to carry out this activity, this is a way to exemplify a simple and quick process to be implemented.
Suppose we need to send a list of the bestselling products in the last seven days and for that we created the query below:
Below we make minor adjustments to the query, to format the result so that it is sent by email and has a more readable look.
- We apply the <li> tag to list all data set records
- Next, we wrap the list of items with the HTML <ul> tag.
The result of the query is not visually beautiful, since the result in HTML 🙂
Now we are going to create our Logic App with a recurrence trigger, query execution and an action “Send an email”
We will schedule for the application to run daily at 8pm.
To make it easier we will execute the SQL command directly, however we could choose to execute a procedure. It is important to configure the authentication method.
Now we just need to select the platform that will trigger the email, in this case it is configured to trigger by a Gmail account. In addition to the possibility of adding extra text to the body of the email, we can also use formulas to collect other information.
Importantly, as the result of a query can be more than one line, this action will create a loop that will be executed for each line, however our query will always return only one line, so only one email will be triggered.
After the execution, we can check if the steps were successfully completed and the execution time.
And we can see the email that will be delivered every day, a simple way to achieve a goal.
Piece of cake, see you the next! 🙂