Change font colour in table cell based on SQL Query in SQL Email

Tony Velarde 1 Reputation point
2020-05-20T00:34:12.897+00:00

Hi All,
I am generating a Report through SQL that emails a set of data results in a HTML table to Fee Earners in our firm. I would like to know, how I can set the font to red when the "Total" is greater than $10,000. The SQL code I have for the Email body is as follows:

SET @tableHTML =
N'<h2 style=''font-family:arial;color:#048a55;''>Fees and Disbursements Report</h2>' +
N'<p style=''font-family:arial;color:#555555;''>This is an automated email. Please review your Fees and Disbursements Report.<br/><br/>Thank you.<br/>Account Team</p>' +
N'<table style=''text-align:center;font-family:arial;color:#555555;font-size:15px'' border="1">' +
N'<tr><th style="background-color: #05fcb6;">Client Code</th><th style="background-color: #05fcb6;">Client Name</th><th style="background-color: #05fcb6;">Matter Code</th>
<th style="background-color: #05fcb6;">Matter Description</th><th style="background-color: #05e7fc;">Total Fees</th>
<th style="background-color: #05e7fc;">Total Disbursements</th><th style="background-color: #05e7fc;">Total</th></tr>' +

CAST ( ( SELECT
td = CLIENT_CODE, '',
'left' AS 'td/@align',
td = CLIENT_NAME, '',
td = MATTER_CODE, '',
'left' AS 'td/@align',
td = LONG_MATT_NAME, '',
'right' AS 'td/@align',
td = '$' + FORMAT(TOTAL_FEES, 'N2'), '',
'right' AS 'td/@align',
td = '$' + FORMAT(TOTAL_DISB, 'N2'), '',
'right' AS 'td/@align',
td = '$' + FORMAT(TOTAL, 'N2'), ''
FROM #WIP_DISB_EMAIL
WHERE EMAIL = @tiedtlaw email
ORDER BY CLIENT_CODE, TOTAL_FEES DESC
FOR XML PATH('tr'), TYPE) AS NVARCHAR(MAX) ) +
N'</table>' +
N'</br></br>' +
+
Any help would be greatly appreciated.
Regards
Tony

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
41,719 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2020-05-20T00:49:23.313+00:00

    QnA currently supports the products listed here (more to be added) Better to reach out to subject matter experts in dedicated forums over here.

    https://social.msdn.microsoft.com/Forums/sqlserver/en-US/home?category=sqlserver

    (please don't forget to mark helpful replies as answer)

    --------------------------

    Regards, Dave Patrick ....
    Microsoft Certified Professional
    Microsoft MVP [Windows Server] Datacenter Management

    Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.


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.