Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Sening email in HTML format

Posted on 2013-12-05
7
Medium Priority
?
321 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
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 

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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

This article will describe one method to parse a delimited string into a table of data.   Why would I do that you ask?  Let's say that you need to pass multiple parameters into a stored procedure to search for.  For our sake, we'll say that we wa…
by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

636 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