none
Send mail the result set of the query

    Question

  • Hi,

    I am trying to send the result set of a query as the file attachment (.txt file).

    The table contains 80 columns with data type Varchar(50).

    But in the output text file, the data is not correct format ( i.e; each row is showing as 3 or 4 multiple rows).

    Here is the query i am executing..

    EXEC MSDB.DBO.SP_SEND_DBMAIL @PROFILE_NAME = @PROFILE_NAME,
    @BODY_FORMAT = 'TEXT',
    @RECIPIENTS= @RECIPIENTS,
    @SUBJECT = 'Result set',
    @QUERY = 'SELECT * FROM <table name>',
    @EXECUTE_QUERY_DATABASE = BW_TEST,
    @ATTACH_QUERY_RESULT_AS_FILE = 1,
    @QUERY_ATTACHMENT_FILENAME= 'ABC.txt',
    @QUERY_RESULT_SEPARATOR = '|',
    @QUERY_RESULT_WIDTH=32766,
    @QUERY_NO_TRUNCATE=1

    --------------------------------------------------------------------------------------

    I tried with @QUERY_RESULT_WIDTH=1024,10000,20000 also, but no use..

    Thanks

    Thursday, April 25, 2013 4:57 AM

Answers

  • Hi Sai.N,

    I tried your codes on my computer and found the format of the attachment “ABC.txt” was correct. I think this was caused by the settings on mail servers, you can try with Windows Hotmail account and check the result again.


    Allen Li
    TechNet Community Support

    Friday, April 26, 2013 5:58 AM

All replies