Solved

Sening email in HTML format

Posted on 2013-12-05
7
291 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
  • 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Where not exists in same table 3 68
SSIS how to COMPARE a data column from different servers? 6 95
How to query LOCK_ESCALATION 4 41
Analysis of table use 7 47
I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

770 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