I'm able to send the query as an attachment by setting @attach_results=true The default atatchment is .txt but is there a way to set it to .xls or .csv? Also to name the attachment? As always thanks for all your help fyi: here's the xp_sendmail syntax xp_sendmail { [ @recipients= ] 'recipients [ ;...n ]' } [ ,[ @message= ] 'message' ] [ ,[ @query= ] 'query' ] [ ,[ @attachments= ] 'attachments [ ;...n ]' ] [ ,[ @copy_recipients= ] 'copy_recipients [ ;...n ]' [ ,[ @blind_copy_recipients= ] 'blind_copy_recipients [ ;...n ]' [ ,[ @subject= ] 'subject' ] [ ,[ @type= ] 'type' ] [ ,[ @attach_results= ] 'attach_value' ] [ ,[ @no_output= ] 'output_value' ] [ ,[ @no_header= ] 'header_value' ] [ ,[ @width= ] width ] [ ,[ @separator= ] 'separator' ] [ ,[ @echo_error= ] 'echo_value' ] [ ,[ @set_user= ] 'user' ] [ ,[ @dbuse= ] 'database' ] it's all good
You can use OSQL or ISQL to format the result as a CSV, refer to books online in this case. Satya SKJ Microsoft SQL Server MVP Contributing Editor & Forums Moderator http://www.SQL-Server-Performance.Com This posting is provided AS IS with no rights for the sake of knowledge sharing.
Thanks again Satya. I'm getting closer. I simply set @attachments= 'MyFile.xls' (now all I have to do is find out why the .xls file is not delimited) FYI: Here's a nice article on sending various types of attachments (.csv, xls, .mdb) using xp_sendmail and scaling it for many user request. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsqlpro03/html/sp03f1.asp it's all good
If you want an Excel output, you need to create the Excel file via DTS or some other mechanisim. SQLMail doesn't understand how to create specific types of output files other than raw textfiles.
just realized this. Even with using @separator= ','. Looks like DTS it is. Thanks Haywood. it's all good
Yeah I just forgot about column seperator and only comma is valid for excel to recognise easily, so CSV is nearest format. Satya SKJ Microsoft SQL Server MVP Contributing Editor & Forums Moderator http://www.SQL-Server-Performance.Com This posting is provided AS IS with no rights for the sake of knowledge sharing.