December 4, 2011 at 6:51 pm
Hi everybody,
I want to send an Email from Database Mail, but it is first time for me to deal with it,
i am try to do like that:
DECLARE @tableHTML NVARCHAR(MAX) ;
SET @tableHTML =
(N'<h1>Work Order Report</h1>' +
N'<table border="1">' +
N'<tr><th>Work Order ID</th><th>Product ID</th>' +
N'<th>Name</th><th>Order Qty</th><th>Due Date</th>' +
N'<th>Expected Revenue</th></tr>' +
CAST (( select Users.UserName from Users ) AS NVARCHAR(MAX) ) +
N'</table>') ;
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'myProfile',
@recipients = 'myEmail@hotmail.com',
@subject = 'SQL Report',
@body_format = 'HTML',
@execute_query_database = 'DataBaseName',
@body = @tableHTML;
The email is send successfully but with no body and it give me error that:
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
also i want to data that selected from Database to be displayed in body whereas every row is located in separate line in body
any reply will be appreciated
Thanks
December 5, 2011 at 12:03 am
Is your query "select Users.UserName from Users" producing results ?
Are there usernames that return NULL in stead of a valid value ?
Did you notice
Msg 512, Level 16, State 1, Line 3
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
Johan
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- How to prevent a sore throat after hours of presenting ppt
press F1 for solution, press shift+F1 for urgent solution 😀
Need a bit of Powershell? How about this
Who am I ? Sometimes this is me but most of the time this is me
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply