?
Solved

Sening email in HTML format

Posted on 2013-12-05
7
Medium Priority
?
315 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 66

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 66

Accepted Solution

by:
Jim Horn earned 1200 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 

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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

777 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