在存储过程中,当我从表中获取数据并设置为xml格式时。我想在标签中设置背景颜色

时间:2017-03-23 16:06:09

标签: sql-server xml

当我以xml格式解析日期行时,根据td设置背景颜色

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

1 个答案:

答案 0 :(得分:0)

你应该

如果您真的想继续上述内容,可以尝试以下方法:

<td>

与引入一般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 属性的方式相同......