changing the font size of a table for html email

  • Hi, I'm using the BOL format for emailing this table. It looks ok, but everything is huge. I've successfully changed the font size of the table headers, but I am unable to get the td's a smaller size.

    I've tried a number of other email scripts on this site with zero success. Any help would be greatly appreciated

    SET @tableHTML =

    N'<H1>Backup Status</H1>' +

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

    N'<tr><th><font size = 1>Current Date</font></th>' +

    N'<th><font size = 1>Server Name</font></th>' +

    N'<th><font size = 1>Database Name</font></th>' +

    N'<th><font size = 1>Last Full Back</font></th>' +

    N'<th><font size = 1>Last Diff Back</font></th>' +

    N'<th><font size = 1>Last TL Back</font></th>' +

    N'<th><font size = 1>Status</font></th>' +

    CAST ( ( SELECT td = CONVERT(VARCHAR(20),GETDATE()), ''

    , td = ServerName, ''

    , td = DatabaseName, ''

    , td = convert(varchar(20),LastFullBackupTime), ''

    , td = convert(varchar(20),LastDifferentialBackupTime), ''

    , td = convert(varchar(20),LastTLBackupTime), ''

    , td = Information

    FROM BackupDW.dbo.DatabaseBackupHistory

    WHERE LEFT(RunDT,11) = LEFT(GETDATE(),11)

    ORDER BY ServerName,DatabaseName

    FOR XML PATH('tr'), TYPE

    ) AS NVARCHAR(MAX) ) +

    N'</table>' ;

  • There are a few things wrong about whatever example you are referring to. The first problem is they are using the < font > tag. This is deprecated in HTML 4. You should use style instead. Also, if you want to set the font-size for the whole table put the font-size on the table instead of each and every element.

    Try this and see if this gets you what you are looking for.

    select

    N'<H1>Backup Status</H1>' +

    N'<table border="1" style="font-size:8px;">' +

    N'<tr><th>Current Date</th>' +

    N'<th>Server Name</th>' +

    N'<th>Database Name</th>' +

    N'<th>Last Full Back</th>' +

    N'<th>Last Diff Back</th>' +

    N'<th>Last TL Back</th>' +

    N'<th>Status</th></tr>' +

    CAST ( ( SELECT 'td' = CONVERT(VARCHAR(20),GETDATE()), ''

    , td = ServerName, ''

    , td = DatabaseName, ''

    , td = convert(varchar(20),LastFullBackupTime), ''

    , td = convert(varchar(20),LastDifferentialBackupTime), ''

    , td = convert(varchar(20),LastTLBackupTime), ''

    , td = Information

    FROM DatabaseBackupHistory

    WHERE LEFT(RunDT,11) = LEFT(GETDATE(),11)

    ORDER BY ServerName,DatabaseName

    FOR XML PATH('tr'), TYPE

    ) AS NVARCHAR(MAX) ) +

    N'</table>' ;

    Notice I removed the font tag on your headers and just added a font-size style to the whole table. If you want to control the size using exact pixels is more accurate (and less subject to user settings) than using a number.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • I'll give that a try thank you. The example is straight from BOL's db_sendmail example. I actually added the (now deprecated) font tag. I'll give that a shot, thanks again.

    Edit: you rock! thanks!

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

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