I already used this method, but now I have to use some colors depending on the values. So, I have the following information in a table:
Material | Q1 | Q2
------
Here is another option. Not clear if you wanted just the one cell highlighted
EDIT - Updated for 3 colors
Example
DECLARE @html varchar(MAX)
SET @html = '
q1
q2
Compare
'+
(
SELECT [td/@style] = 'background:'+choose(sign(q1-q2)+2,'blue;color:white;','yellow','red')
,[td] = isnull(q1,0)
,null
,[td/@style] = 'background:'+choose(sign(q1-q2)+2,'blue;color:white;','yellow','red')
,[td] = isnull(q2,0)
,null
,[td/@style] = 'background:'+choose(sign(q1-q2)+2,'blue;color:white;','yellow','red')
,[td] = name
FROM #tempo
FOR XML PATH('tr')
)
+'
'
SELECT @html
Returns