SQL Server Performance

xp_sendmail attach excel file

Discussion in 'General DBA Questions' started by kingofSQL, Aug 28, 2006.

  1. kingofSQL New Member


    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
  2. satya Moderator

    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.
  3. kingofSQL New Member

  4. Haywood New Member

    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.
  5. kingofSQL New Member

    just realized this. Even with using @separator= ','. Looks like DTS it is.

    Thanks Haywood.

    it's all good
  6. satya Moderator

    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.

Share This Page