MSSQL SQL Server uses a method to share HTML information that alternates between different background colors

Source: Internet
Author: User
Tags mssql

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.