Solved

Sening email in HTML format

Posted on 2013-12-05
7
301 Views
Last Modified: 2013-12-05
Experts,

I am using the following code to send an email and getting the following error and I am displaying two values. Any help is much appreciated.

=============================================================
Msg 116, Level 16, State 1, Procedure Abc_Email, Line 86
Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.
=============================================================
DECLARE @tableHTML  NVARCHAR(MAX) ;

SET @tableHTML =
    N'<H1>My Data</H1>' +
    N'<table border="1">' +
    N'<tr><th>Total Values</th></tr>' +  
      N'<tr><th>Loaded Values</th></tr>' +  
    CAST ( ( SELECT td = @TotalData,
                              td = @TotalLoaded                        
                   
                     ) AS NVARCHAR(MAX) ) +
    N'</table>' ;

EXEC msdb.dbo.sp_send_dbmail @recipients='myemail@abc.com',
    @subject = 'Data Details',
    @body = @tableHTML,
    @body_format = 'HTML' ;
0
Comment
Question by:Tpaul_10
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
7 Comments
 
LVL 65

Expert Comment

by:Jim Horn
ID: 39699645
>SELECT td = @TotalData,  td = @TotalLoaded
...shouldn't this be...
'SELECT ' + @TotalData + ', ' + @TotalLoaded

Show us how these two variables are populated.
0
 

Author Comment

by:Tpaul_10
ID: 39699712
I have it like following and using those variables in the email

SELECT @TotalData = COUNT(*) FROM mydb.mytable1
SELECT @TotalLoaded  = COUNT(*) FROM mydb.mytable2

Thank You
0
 
LVL 65

Accepted Solution

by:
Jim Horn earned 300 total points
ID: 39699718
ok.

(1)  Please explain what you're intent is here, as I don't see a table name.
SELECT td = @TotalData,

(2)  I get the CAST(.. as NVARCHAR(max), but the SELECT .. COUNT(*) will return an int, so you'll have to CAST both of those as NVARCHAR(max) {or whatever char data type} in order to concatenate them with the rest of the string.
0
Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

 

Author Comment

by:Tpaul_10
ID: 39699738
I am trying to send an email with the following details (like an HTML format), would be happy to see another way to do it as well.

Data load details
Total Values : Value of @TotalData
Loaded Values : Value of @TotalLoaded  

If I just have SELECT td = @TotalData, I am getting the email successfully and when I add second variable to the list getting the error I have specified above.

Also, if I give multiple email addresses with ; as the delimiter not working as well.

Thank you, appreciate all your help.
0
 

Author Comment

by:Tpaul_10
ID: 39699745
0
 

Author Comment

by:Tpaul_10
ID: 39700290
I've requested that this question be closed as follows:

Accepted answer: 0 points for Tpaul_10's comment #a39699738

for the following reason:

Thank you
0
 

Author Closing Comment

by:Tpaul_10
ID: 39700291
Thanks
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you having speed problem in loading SQL Server Management Studio, try to uncheck these options in your internet browser (IE -> Internet Options / Advanced / Security):    . Check for publisher's certificate revocation    . Check for server ce…
I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question