﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2008 / SQL Server Newbies  / html from sql server 2K8R2 / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Wed, 22 May 2013 10:41:26 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: html from sql server 2K8R2</title><link>http://www.sqlservercentral.com/Forums/Topic1385334-1292-1.aspx</link><description>Alan, Sorry for delay, but better later than never. Thank you. That is what I was looking for.Eugene</description><pubDate>Wed, 05 Dec 2012 14:30:41 GMT</pubDate><dc:creator>rightontarget</dc:creator></item><item><title>RE: html from sql server 2K8R2</title><link>http://www.sqlservercentral.com/Forums/Topic1385334-1292-1.aspx</link><description>I don't have a specific example to show you, but another approach is to use the SELECT command using the FOR XML switch.  Then use XSLT transformations to convert to the target format.  ;-)</description><pubDate>Sun, 02 Dec 2012 23:41:51 GMT</pubDate><dc:creator>Brandon Forest</dc:creator></item><item><title>RE: html from sql server 2K8R2</title><link>http://www.sqlservercentral.com/Forums/Topic1385334-1292-1.aspx</link><description>[quote][b]eugene.pipko (11/27/2012)[/b][hr]Thanks, what if I need to change font-weight at &amp;lt;tr&amp;gt; level?How do I access &amp;lt;tr&amp;gt;?[/quote]The top row (the first instance of the TR tag) you could add any attributes just like you would by writing the HTML like so:[code="xml"]N'&amp;lt;tr style=''font-family: arial black;''&amp;gt;&amp;lt;th&amp;gt;InsertDate&amp;lt;/th&amp;gt;&amp;lt;th&amp;gt;WebServerName&amp;lt;/th&amp;gt;&amp;lt;th&amp;gt;Location&amp;lt;/th&amp;gt;&amp;lt;th&amp;gt;Total Records&amp;lt;/th&amp;gt;&amp;lt;th&amp;gt;Failed Records&amp;lt;/th&amp;gt;' +[/code]There are a number of other ways... Let's say you wanted to access all the rows (&amp;lt;tr&amp;gt;'s), you could add a style sheet in the static HTML portion as follows: [code="sql"]SET @tableHTML =	N'&amp;lt;style&amp;gt; tr {font-family: Segoe Script;}&amp;lt;/style&amp;gt;' +     N'&amp;lt;H3&amp;gt;Daily Failure Report&amp;lt;/H3&amp;gt;' +[/code]What is going on here is a mix of HTML and CSS; again, W3schools.com is the place to get a grasp of HTML, CSS, XML, etc.. Below is a sample that you can use as a reference. Notice how I change the first row (the 1st &amp;lt;tr&amp;gt;), all the rows (all &amp;lt;tr&amp;gt;'s) and all the cells (the &amp;lt;td&amp;gt;'s)This:[code="sql"]IF (OBJECT_ID('tempdb..#tmpDailyReport') IS NOT NULL)DROP TABLE #tmpDailyReportCREATE TABLE #tmpDailyReport(   Date varchar( 12 )     Null,   WebServerName         varchar( 150 ) NOT Null,   Location         varchar( 150 ) NOT Null,   cnt_RecsTotal    int Null,   cnt_RecsFailed   int Null)INSERT INTO #tmpDailyReport(   Date, WebServerName, Location, cnt_RecsTotal,cnt_RecsFailed)select '2008-01-01','Amsterdam-Server','Amsterdam',1000,2unionselect '2008-01-01','London-Server','London Bridge',50,0unionselect '2008-01-01','London-Server','London West Minster',80,0unionselect '2008-01-01','Portugal-Server','Lisbon',5,1--SELECT * FROM #tmpDailyReportDECLARE @tableHTML  NVARCHAR(MAX) ;SET @tableHTML =	N'&amp;lt;style&amp;gt; tr {font-family: Segoe Script;}&amp;lt;/style&amp;gt;' +     N'&amp;lt;H3&amp;gt;Daily Failure Report&amp;lt;/H3&amp;gt;' +    N'&amp;lt;div&amp;gt;&amp;lt;H5&amp;gt;Execution Date: &amp;lt;font color="blue"&amp;gt;' + CONVERT(NVARCHAR(30), GETDATE(), 113) + '&amp;lt;/FONT&amp;gt;&amp;lt;/H5&amp;gt;&amp;lt;/div&amp;gt;' +    N'&amp;lt;table border="1"&amp;gt;' +    N'&amp;lt;tr style=''font-family: arial black;''&amp;gt;&amp;lt;th&amp;gt;InsertDate&amp;lt;/th&amp;gt;&amp;lt;th&amp;gt;WebServerName&amp;lt;/th&amp;gt;&amp;lt;th&amp;gt;Location&amp;lt;/th&amp;gt;&amp;lt;th&amp;gt;Total Records&amp;lt;/th&amp;gt;&amp;lt;th&amp;gt;Failed Records&amp;lt;/th&amp;gt;' +    CAST ( (	SELECT	td = Date, '', 			td = WebServerName, '', 			td = Location, '', 			td = cnt_RecsTotal, '',			'td/@style' = CASE WHEN cnt_RecsFailed &amp;gt; 0 THEN 'font-weight: bold; color: pink;' END,			td = cnt_RecsFailed	FROM #tmpDailyReport	for xml path('tr'), TYPE) AS NVARCHAR(MAX) ) +    N'&amp;lt;/table&amp;gt;' +    N'';SELECT @tableHTMLdrop table #tmpDailyReport [/code]Will produce this: [code="xml"]&amp;lt;style&amp;gt; tr {font-family: Segoe Script;}&amp;lt;/style&amp;gt;&amp;lt;H3&amp;gt;Daily Failure Report&amp;lt;/H3&amp;gt;&amp;lt;div&amp;gt;&amp;lt;H5&amp;gt;Execution Date: &amp;lt;font color="blue"&amp;gt;27 Nov 2012 14:30:21:433&amp;lt;/FONT&amp;gt;&amp;lt;/H5&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;table border="1"&amp;gt;&amp;lt;tr style='font-family: arial black;'&amp;gt;&amp;lt;th&amp;gt;InsertDate&amp;lt;/th&amp;gt;&amp;lt;th&amp;gt;WebServerName&amp;lt;/th&amp;gt;&amp;lt;th&amp;gt;Location&amp;lt;/th&amp;gt;&amp;lt;th&amp;gt;Total Records&amp;lt;/th&amp;gt;&amp;lt;th&amp;gt;Failed Records&amp;lt;/th&amp;gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;2008-01-01&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Amsterdam-Server&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Amsterdam&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;1000&amp;lt;/td&amp;gt;&amp;lt;td style="font-weight: bold; color: pink;"&amp;gt;2&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;2008-01-01&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;London-Server&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;London Bridge&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;50&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;0&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;2008-01-01&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;London-Server&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;London West Minster&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;80&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;0&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;2008-01-01&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Portugal-Server&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Lisbon&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;5&amp;lt;/td&amp;gt;&amp;lt;td style="font-weight: bold; color: pink;"&amp;gt;1&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;/table&amp;gt;[/code]Edited: Code sample got jacked up...</description><pubDate>Tue, 27 Nov 2012 13:38:18 GMT</pubDate><dc:creator>Alan.B</dc:creator></item><item><title>RE: html from sql server 2K8R2</title><link>http://www.sqlservercentral.com/Forums/Topic1385334-1292-1.aspx</link><description>Thanks, what if I need to change font-weight at &amp;lt;tr&amp;gt; level?How do I access &amp;lt;tr&amp;gt;?</description><pubDate>Tue, 27 Nov 2012 12:07:30 GMT</pubDate><dc:creator>rightontarget</dc:creator></item><item><title>RE: html from sql server 2K8R2</title><link>http://www.sqlservercentral.com/Forums/Topic1385334-1292-1.aspx</link><description>[quote][b]eugene.pipko (11/19/2012)[/b][hr]Thank you for reply,So, for every &amp;lt;td&amp;gt;, if I need to change an attribute, I'd need to select 'td/@style' = ......?Thanks,[/quote]Yes. P.S. W3Schools is the best place to go for an HTML reference.</description><pubDate>Mon, 26 Nov 2012 16:15:03 GMT</pubDate><dc:creator>Alan.B</dc:creator></item><item><title>RE: html from sql server 2K8R2</title><link>http://www.sqlservercentral.com/Forums/Topic1385334-1292-1.aspx</link><description>Thank you for reply,So, for every &amp;lt;td&amp;gt;, if I need to change an attribute, I'd need to select 'td/@style' = ......?Thanks,</description><pubDate>Mon, 19 Nov 2012 09:14:03 GMT</pubDate><dc:creator>rightontarget</dc:creator></item><item><title>RE: html from sql server 2K8R2</title><link>http://www.sqlservercentral.com/Forums/Topic1385334-1292-1.aspx</link><description>This seems to be more of an HTML/CSS formatting question than a SQL Server question, so perhaps try this:1. Take the HTML created by the code you posted and output it with: select @tableHTML 2. Paste that output into Notepad and view it in a web browser.3. Manually edit it by trial and error it until you get the desired result using references such as the "[url=http://www.w3schools.com/html/html_css.asp]HTML Style Example - Font, Color and Size[/url]" example at w3schools.4. Put the formatting want back into the T-SQL.For example, this code makes the font of the red cells larger and they are sorted/ORDERed BY the number of failed records.  (Is sorting what you meant by controlling the position of tr?) [code="sql"]SELECT td = Date, '', td = WebServerName, '', td = Location, '', td = cnt_RecsTotal, '','td/@style' = CASE WHEN cnt_RecsFailed &amp;gt; 0 THEN 'background-color:#FF3366; font-size:20pt;' END,td = cnt_RecsFailedFROM #tmpDailyReportORDER BY cnt_RecsFailedfor xml path('tr'), TYPE    ) AS NVARCHAR(MAX) ) +    N'&amp;lt;/table&amp;gt;' +    N'' ;[/code]</description><pubDate>Sat, 17 Nov 2012 16:38:06 GMT</pubDate><dc:creator>George Rypysc</dc:creator></item><item><title>html from sql server 2K8R2</title><link>http://www.sqlservercentral.com/Forums/Topic1385334-1292-1.aspx</link><description>Hi all,I am trying to generate an HTML-formated email from sql server. I need to be able to control the font-size/position of the table cell &amp;lt;td&amp;gt; or table row &amp;lt;tr&amp;gt;.Here is the link of the sample I am trying to follow: [url]http://grounding.co.za/blogs/romiko/archive/2008/09/21/generating-professional-email-notifications-with-sql.aspx[/url]Could someone help?[code="sql"]IF (OBJECT_ID('#tmpDailyReport') IS NOT NULL)DROP TABLE #tmpDailyReportCREATE TABLE #tmpDailyReport(   Date varchar( 12 )     Null,   WebServerName         varchar( 150 ) NOT Null,   Location         varchar( 150 ) NOT Null,   cnt_RecsTotal    int Null,   cnt_RecsFailed   int Null)INSERT INTO #tmpDailyReport(   Date, WebServerName, Location, cnt_RecsTotal,cnt_RecsFailed)select '2008-01-01','Amsterdam-Server','Amsterdam',1000,2unionselect '2008-01-01','London-Server','London Bridge',50,0unionselect '2008-01-01','London-Server','London West Minster',80,0unionselect '2008-01-01','Portugal-Server','Lisbon',5,1DECLARE @tableHTML  NVARCHAR(MAX) ;SET @tableHTML =    N'&amp;lt;H3&amp;gt;Daily Failure Report&amp;lt;/H3&amp;gt;' +      N'&amp;lt;div&amp;gt;&amp;lt;H5&amp;gt;Execution Date: &amp;lt;font color="blue"&amp;gt;' + CONVERT(NVARCHAR(30), GETDATE(), 113) + '&amp;lt;/FONT&amp;gt;&amp;lt;/H5&amp;gt;&amp;lt;/div&amp;gt;' +    N'&amp;lt;table border="1"&amp;gt;' +    N'&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;InsertDate&amp;lt;/th&amp;gt;&amp;lt;th&amp;gt;WebServerName&amp;lt;/th&amp;gt;&amp;lt;th&amp;gt;Location&amp;lt;/th&amp;gt;&amp;lt;th&amp;gt;Total Records&amp;lt;/th&amp;gt;&amp;lt;th&amp;gt;Failed Records&amp;lt;/th&amp;gt;' +    CAST ( (SELECT td = Date, '', td = WebServerName, '', td = Location, '', td = cnt_RecsTotal, '','td/@bgcolor' = CASE WHEN cnt_RecsFailed &amp;gt; 0 THEN '#FF3366' END,td = cnt_RecsFailedFROM #tmpDailyReportfor xml path('tr'), TYPE    ) AS NVARCHAR(MAX) ) +    N'&amp;lt;/table&amp;gt;' +    N'' ;drop table #tmpDailyReport [/code]Thanks,</description><pubDate>Thu, 15 Nov 2012 13:18:12 GMT</pubDate><dc:creator>rightontarget</dc:creator></item></channel></rss>