mssql sqlserver 使用sql脚本输出交替不同的背景色的html信息的方法分享


摘要:
下文将分享使用sql脚本输出交替变换的不同背景颜色的sql脚本的方法分享,如下所示:
实验环境:sqlserver 2008 R2


例:
下文 首先采用 over() row_number 函数生成的行编号,
然后对每行进行颜色变化操作,生成不同的背景色,如下所示:

     create table test(keyId int,info varchar(30))
	  go
	  insert into test(keyId,info)values(10,'测试信息20180625-1')
	  insert into test(keyId,info)values(20,'测试信息20180626-2')
	  insert into test(keyId,info)values(21,'测试信息20180628-3')
	  insert into test(keyId,info)values(81,'测试信息20180620-4')
	  insert into test(keyId,info)values(92,'测试信息20180608-5')
	  insert into test(keyId,info)values(101,'测试信息20180605-6')
	  insert into test(keyId,info)values(102,'测试信息20180606-7')
	 go


declare @tmp varchar(max)
set @tmp =''
set @tmp =@tmp+''

select 
@tmp=@tmp+''
+''
  from 
(
select row_number() over(order by keyId asc ) as [编号],
keyId,info from test ) as t 
 
 
set @tmp =@tmp+'
流水号keyIdinfo
'+ convert(varchar(100),t.[编号]) +''+ convert(varchar(100),t.keyId) +''+t.info +'
' select @tmp ---打印生成的html信息 go drop table test