How to use colors in my HTML heading and also printing colors to the failure/DBCC CHECKDB error?

  • Hi,

    I need to print in RED if there's atleast 1 or more consistency error and need a heading color of the table (Caption) Plz suggest how to do it.

    DECLARE @tableHTML NVARCHAR(MAX) ;

    SET @tableHTML =

    N'<H1>DB Corruption Report:</H1>' +

    N'<table border="1">' +

    N'<tr><th>DBName</th><th>MessageText</th>' +

    N'<th>ObjName</th><th>Error</th><th>TimeStamp</th>' +

    CAST ( ( SELECT td = DBName, '',

    td = MessageText, '',

    td = ISNULL(ObjName,'NO Data Found'), '',

    td = Error, '',

    td = TimeStamp

    FROM [dbo].[dbcc_check_history]

    ORDER By DBName

    FOR XML PATH('tr'), ELEMENTS

    ) AS NVARCHAR(MAX) ) +

    N'</table>' ;

    SELECT (@tableHTML)

    Thanks.

  • Are you looking for conditional HTML or are you just going to create another statement with the red font? The easy way would be to use an if statement. You can also dynamically generate the html and use case statements.

    The syntax just looks like this,

    <font size="3" color="red">SQL!</font>

    Or you can do something like this,

    DECLARE @tableHTML NVARCHAR(MAX) ;

    declare @error int

    set @error=1

    SET @tableHTML =

    case when @error>0 then N'<font color = "red"><H1>DB Corruption Report:</H1></font>' else N'<H1>DB Corruption Report:</H1>' end +

    N'<table border="1">' +

    N'<tr><th>DBName</th><th>MessageText</th>' +

    N'<th>ObjName</th><th>Error</th><th>TimeStamp</th>'

    SELECT (@tableHTML)

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply