Transferred from: http://www.maomao365.com/?p=6679
Summary:
The following is a shared method of sharing SQL scripts that use the different background colors of the SQL script output alternate transformation, as follows:
Lab environment: SQL Server R2
Cases:
The following first uses the row number generated by the over () Row_number function,
Then make a color change operation on each line, producing a different background color, as shown below:
Create TableTest (keyIdint, infovarchar( -))GoInsert intoTest (Keyid,info)Values(Ten,'Test Information 20180625-1')Insert intoTest (Keyid,info)Values( -,'Test Information 20180626-2')Insert intoTest (Keyid,info)Values( +,'Test Information 20180628-3')Insert intoTest (Keyid,info)Values(Bayi,'Test Information 20180620-4')Insert intoTest (Keyid,info)Values( the,'Test Information 20180608-5')Insert intoTest (Keyid,info)Values(101,'Test Information 20180605-6')Insert intoTest (Keyid,info)Values(102,'Test Information 20180606-7')GoDeclare @tmp varchar(Max)Set @tmp ='<table>'Set @tmp =@tmp+'<tr><td> serial number <td>keyId<td>info</tr>'Select @tmp=@tmp+'<tr style="'Background-color:'+ Case whenT.[numbering] %2=0 Then 'Blue' Else "' End+" ">'+'<td>'+ Convert(varchar( -), T.[numbering])+'<td>'+ Convert(varchar( -), T.keyid)+'<td>'+T.info+'</tr>' from (SelectRow_number () Over(Order byKeyIdASC) as [numbering], Keyid,info fromTest) asTSet @tmp =@tmp+'</table>'Select @tmp ---Print generated HTML informationGoDrop TableTest
MSSQL SQL Server uses a method to share HTML information that alternates between different background colors