Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Sending an HTML e-mail message

Author  Topic 

raky
Aged Yak Warrior

767 Posts

Posted - 2010-02-16 : 07:35:08

Hi,

Iam trying to send the output of a query as an HTML e-mail message.
the query gives nearly 3000 records as output but iam getting only 278 records in HTML e-mail message. How can i get all the records of the query as an Html e-mail message. Please help...

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-16 : 12:26:39
how are you sending email? using sp_send_dbmail or send mail task in ssis?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 2010-02-17 : 01:07:42

using sp_send_dbmail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-17 : 01:09:06
and you've checked you're getting the record count as 3000 when executing same query in QA?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 2010-02-17 : 01:20:12
My Query looks like this

DECLARE @tableHTML NVARCHAR(MAX), @MailSubject VARCHAR(100)

SELECT @MailSubject = 'QueryResults as on '+ CONVERT(VARCHAR(20), GETDATE(), 100)

SET @tableHTML =
N'<H1>QueryResults</H1>' +
N'<table border="1">' +
N'<tr><th>ID</th>' +
N'<th>Name</th>' +
N'<th>Date</th>' +
N'<th>Value</th>' +
N'<th>createdby</th></tr>' +
CAST ( ( SELECT
td = ISNULL(T.ID,'NULL'), '',
td = ISNULL(T.Name,'NULL'), '',
td = ISNULL(CONVERT(VARCHAR(20),T.Date, 100),'NULL'), '',
td = ISNULL(T1.Value,'NULL'), '',
td = ISNULL(T2.createdby,'NULL'), ''
FROM
dbo.Test T
INNER JOIN
dbo.Test1 T1 ON T.AID = T1.BID
INNER JOIN
dbo.Test2 T2 ON T.TDID = T2.TDID
WHERE
T2.MinID = 5
AND T2.GPID = 12
AND T1.LID = 8
ORDER BY 1
FOR XML PATH('tr'), TYPE
) AS NVARCHAR(MAX) ) +
N'</table>' ;

-- To get Column Header when no values are returned by the query
SELECT @tableHTML = ISNULL(@tableHTML,'<H1>QueryResults</H1><table border="1"><tr><th>ID</th><th>Name</th><th>Date</th><th>Value</th><th>createdby</th></tr>')


EXEC msdb.dbo.sp_send_dbmail @recipients='xyz@gmail.com', --recipients email list
@subject = @MailSubject,
@profile_name = 'MyMailProfile',
@body = @tableHTML,
@body_format = 'HTML' ;

Here @tableHTML is not able to hold all values in the result set returned by the query.

Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 2010-02-17 : 01:22:17
quote:
Originally posted by visakh16

and you've checked you're getting the record count as 3000 when executing same query in QA?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/





Ya i cross checked the records count by executing the query and the number of records in E-Mail Message. Both are differing.
Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 2010-02-17 : 02:35:59
Does any one got the solution for my problem??
Go to Top of Page
   

- Advertisement -