Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Email and CSS in T-SQL 1

Status
Not open for further replies.

nice95gle

Programmer
Nov 25, 2003
359
US
Wow...it's been a while since I posted or asked a question.

I writing some html in my script which sends out an email and I wanted to use a style sheet, but for some reason it's not working.

If I take the results of @MyHTML and paste it into notepad, save it as a html file and open it in a browser it works great.
But if I email the results, the table and data shows in my email. But no formatting as if it's completely bypassing the style sheet.

I'm thinking that my email server can't see the server where my CSS is located.
But I wanted to place it out there. And hear what you guys had to say.

If it's not possible to get a style sheet to work. I'll just use the <style> tag and embed my style directly into my proc.

I can't attach any real code because of security. but I'll try my best.

Code:
SET @MyHTML = 
N'<link rel="stylesheet" type="text/css" href="\\Server\Share\file.css">'+
N'<caption><font face="verdana" color="Red">TITLE 1</font></caption>'+
N'<table class="clsBasicFmt" >' +
N'<tr><th>Field1</th>
<th>Field2</th>
<th>Field3</th>
<th>Field4</th>
<th>Field5</th>
<th>Field6</th>
<th>Field7</th>
</tr>' +
CAST ( ( 
SELECT td = CONVERT(VARCHAR(100),[Field1]),'',
td = Field2,'',
td = Field3,'',
td = Field4,'',
td = Field5,'',
td = Field6,'',
td = CONVERT(VARCHAR(30),[Field7],120) 
FROM MyDataSource 
ORDER BY [Field1]
FOR XML PATH('tr'), TYPE 
) AS NVARCHAR(MAX) ) +
N'</table>' + '<br>'+

N'<caption><font face="verdana" color="Red">TITLE 2</font></caption>' +
N'<table class="clsBasicFmt" >'+
N'<tr><th>Field1</th> 
<th>Field2</th>
<th>Field3</th>
<th>Field4</th>
<th>Field5</th>
<th>Field6</th>
<th>Field7</th>
<th>Field8</th>
</tr>' +
CAST ( ( 
SELECT 
td = ISNULL(ROW_NUMBER() over (order by Field1),''),'', 
td = ISNULL(CONVERT(VARCHAR(100),[Field2]),'') , '',
td = ISNULL([Field3],'') ,'',
td = ISNULL([Field1],''),'',
td = ISNULL([Field4],'') ,'',
td = ISNULL(CONVERT(VARCHAR(10),[Field5]),'') , '',
td = ISNULL([Field6],'') , '',
td = ISNULL(CONVERT(VARCHAR(30),[Field7],120),'') 
FROM MyDataSource2
ORDER BY [Field2]
FOR XML PATH('tr'), TYPE 
) AS NVARCHAR(MAX) ) +
N'</table>'

--SELECT @MyHTML

EXEC msdb.dbo.sp_send_dbmail
	  @PROFILE_NAME = @Profile,		
	  @Recipients = 'Recipients list',
	  @body = @MyHTML,
	  @body_format = 'HTML',
	  @SUBJECT = @Subject

Well Done is better than well said
- Ben Franklin
 
This will not work in your sql string. It will only work on an HTML page.
Code:
<link rel="stylesheet" type="text/css" href="\\Server\Share\file.css">

I would suggest using a front end app to format and send the email. Sql is not meant or designed for this.
 
Thanks, that's all I needed to hear.
I don't really understand style sheets and how they do or don't interact with SQL SERVER.

Well Done is better than well said
- Ben Franklin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top