使用存储过程有条件地格式化我的HTML报告?



我使用SQL Server存储过程和HTML开发了这段代码,以发送一个自动报告,检查数据中的差异,但我想突出显示增量列中不等于0的数字。是否有一种方法可以用红色(例如)突出显示零,用绿色突出显示非零?

我把报告附在这里,用黄色突出显示的部分需要用HTML条件格式突出显示

SET @tableHTML1 = 
+ N' <p>This report is driven by <b>DWQC.dbo.mwsp_QC_EM_LS_EPMS_DAILY_CHECK  </b> stored procedure.
Each METRIC in the QC is compared between the Source,House and Mart databases,  
and the resulting delta is displayed </p>'

+N'<style type="text/css">' + N'.tg  {border-collapse:collapse;border-spacing:0;border-color:#aaa;}'
+ N'.tg td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:#aaa;color:#333;background-color:#fff;}'
+ N'.tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:#aaa;color:#fff;background-color:#808080;}'
+ N'.tg .tg-9ajh{font-weight:bold;background-color:#808080}' + N'.tg .tg-hgcj{font-weight:bold;text-align:center}'
+ N'</style>' -- contains all the styling for the HTML report
+ N'<table class="tg">'  -- calls the table to included in the report
+ N'<th class="tg-hgcj">CHECK_ID </th>'
+ N'<th class="tg-hgcj">CHECK NAME </th>'
+ N'<th class="tg-hgcj">SOURCE_COUNT</th>'
+ N'<th class="tg-hgcj">TARGET_COUNT</th>'
+ N'<th class="tg-hgcj">DELTA</th>' 
+ N'</tr>'   
+ CAST ( (select  -- checks for columns that could be seen in attached report
td=CHECK_ID,'',
td=CHECK_NAME,'',   
td=SOURCE_COUNT,'', 
td=TARGET_COUNT,'', 
td=DELTA,'' 
from( Select top 1000
isnull(CHECK_ID,0) as CHECK_ID,     
isnull(CHECK_NAME,0) as CHECK_NAME, 
isnull(SOURCE_COUNT,0) as SOURCE_COUNT, 
isnull(TARGET_COUNT,0) as TARGET_COUNT, 
isnull(DELTA,0) as DELTA 
from #table  --contains the data to be used in the report; temporarily naming it "table"
order by RID)Q
FOR XML PATH('tr'),
TYPE
) AS NVARCHAR(MAX))
+ N'</table>' 

提前感谢!!

td=TARGET_COUNT,'', 
[td/@class]=case when DELTA > 0 then 'highlightmeclass' end, 
-- Or… [td/@bgcolor]= case when DELTA > 0 then 'yellow' end,
td=DELTA,'' 

.

最新更新