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 2008 Forums
 Transact-SQL (2008)
 Excel Document as attachment via dbmail

Author  Topic 

jimdarter
Starting Member

14 Posts

Posted - 2014-10-19 : 11:28:53
Hello All,

I'm trying to export the results of a query in an excel file and send that file via attachment in an email. The issue that I am facing is that the excel file is not properly formatted as it is a csv. I tried a tab-delimited format as well and even that is distorted. Can someone please suggest me the best way to send an excel file using this dbmail procedure?

Also, in my query I just have two columns right now.


DECLARE
@csv char(1)
BEGIN
set @csv= ','


EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'nationstar University',
@recipients = 'donald@nation.com',
@query = 'select FNAME,LNAME from PED.dbo.TD_EmployeeProfile_FinalV2 where manager_number=100000491' ,
@subject = 'Test email',
@attach_query_result_as_file = 1,
@query_attachment_filename='filename.xls',
@query_result_separator=@tab,
@query_result_no_padding=1
END

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-10-20 : 09:07:47
This would be easier with SSIS.
Go to Top of Page
   

- Advertisement -