0

Set background color based on td when i parse date row in xml format

declare @xml1 xml    
SET @xml1 = CAST((select Region AS 'td','',
      [MTD Total] AS 'td','',
      [MTD] AS 'td','',
      [MTD Percentage] AS 'td','',
      [FTD Total] AS 'td','',
      [FTD] AS 'td','',
      [FTD Percentage] AS 'td',''
FROM #temp
FOR XML PATH('tr'), ELEMENTS ) AS NVARCHAR(MAX))
select  @xml1
  • [Have a look at this answer](http://stackoverflow.com/a/39487565/5089204). You'll find a function to create a HTML table out of any select statement with support for style tags, CSS, links... – Shnugo Mar 24 '17 at 07:47
  • @shnugo u know how to set color by row wise. Column wise color set working fine. – Ghanshyam Kumar Mar 24 '17 at 13:52
  • Sorry, I do not understand what you mean... – Shnugo Mar 24 '17 at 17:13

1 Answers1

0

You should either

If you really want to continue with the above you might try something like this:

declare @xml1 xml =
(   
select
      'blue' AS [td/@bgcolor], 
      Region AS 'td','',
      'red' AS [td/@bgcolor], 
      [MTD Total] AS 'td','',
      'white' AS [td/@bgcolor], 
      [MTD] AS 'td','',
      'green' AS [td/@bgcolor], 
      [MTD Percentage] AS 'td','',
      'yellow' AS [td/@bgcolor], 
      [FTD Total] AS 'td','',
      'black' AS [td/@bgcolor], 
      [FTD] AS 'td','',
      'blue' AS [td/@bgcolor], 
      [FTD Percentage] AS 'td',''
FROM #temp
FOR XML PATH('tr'),TYPE
);

select  @xml1

The same way you might introduce a general style attribute...

Community
  • 1
  • 1
Shnugo
  • 66,100
  • 9
  • 53
  • 114