Customize and output sql query results to an email using Azure Logic Apps

Vivek Komarla Bhaskar 956 Reputation points
2024-01-09T13:03:19.2833333+00:00

Hi,

Screenshot 2024-01-09 at 12.50.40

I am using Logic apps to email the results of a SQL query. Would it be possible to enhance the visual appearance of the SQL query results outputted as a table in the email? As an example,

  1. Adding all border lines to the table
  2. Make the headers bold and add a background color
  3. Make the Footer/Totals row bold and add a background color.

Is there a way for me to accomplish this? I would want my email to look like below -
Screenshot 2024-01-09 at 13.01.53

Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
3,542 questions
{count} votes

Accepted answer
  1. Sonny Gillissen 3,751 Reputation points Volunteer Moderator
    2024-01-09T14:49:26.6+00:00

    Hi Vivek Komarla Bhaskar,

    Thank you for reaching out on Microsoft Q&A!

    I've tested it in my lab, and this is possible by adding CSS to your email.

    It's basically an HTML email, meaning you can style parts using CSS as you would with normal HTML. For this, create a 'Compose' action in your Logic App with the name "CSS" and add in the code below which colors your table (be sure to convert red and blue to the color codes of your liking):

    <style>
    table {
        border-collapse: collapse;
        border-spacing: 0;
    }
    tr, td, th {
        border: 1px solid black;
    }
    th {
        background-color: blue;
        font-weight: bold;
        color: white;
    }
    tr:last-child {
        background-color: red;
        font-weight: bold;
    }
    </style>
    

    Now go to your email action and add the 'CSS' action output on top of your mail using the dynamic content:

    User's image

    When you send the mail it should appear like this:

    User's image

    Please click “Accept answer” if you find this helpful. Feel free to drop additional queries in the comments below.

    Kind regards,

    Sonny

    3 people found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.