sp_send_dbmail

  • Hello,

    I am working on sp_send_dbmail, when i am executing a query and attaching the same. Below is query

    EXEC

    msdb.dbo.sp_send_dbmail

    @profile_name = 'ABC',

    @recipients = 'nag@sat.com',

    @query = 'SELECT * FROM isos_prod..tbl_sourceorders',

    @subject

    = 'Error Log ',

    @attach_query_result_as_file

    = 1 ;

     

    ERROR:

    Msg 22050

    , Level 16, State 1, Line 0

    File

    attachment or query results size exceeds allowable value of 1000000 bytes.

    The error is occuring because this is sending as  txt file where spaces are occupied much in output fiile and i want in the Grid format(xls) instead of text(txt).

    Waiting for Earliest Reply.

     

     

  • Hello Reddy,

    You can change the default parameters to the desired number of bytes. Click on Database Mail -> Select Configure DB Mail -> Next -> Select the radio button "View or Change System Parameters".

    On the next screen, you will see an option for Max. file size, which you can change by clicking or overwriting.

    Hope this helps your requirement. Reply back, how it has helped you.

    Thanks

     


    Lucky

  • Lucky,

    Many Thanks for your reply, The output is still having spaces which i dont require, ex: Name is having varchar(5000) in the output file it is showing 5000 'Luck is a Good Techy guy                 '..till 5000 ends  it will show entire 5000 chars. Basically i need the output as GRID format as a attachment.

    Many Thanks,

     

  • I don't think you can export the grid from Server Management Studio.  I've dealt with similar problems and ended up DTS'ing the package to an Excel format and then attached the Excel file in the email.

  • Another option is to limit the size of the output column. Instead of SELECT name ..., try SELECT CAST(name as varchar(100)) ...

  • Had the same error message and problem.

    Added the following to fix:

    @query_result_no_padding =1

    Hope this helps.

  • it works for me

    Thanks a lot,

    Sarah

  • this requires a hotfix found at http://support.microsoft.com/kb/920794

  • @query_result_no_padding =1

    This worked for me. Big Thanks.

  • here is my sp....i dont get the resultset in columns (not well formatted). can anyone help with this....thanks a lot!!

    EXEC msdb.dbo.sp_send_dbmail

    @profile_name = 'WYZ',

    @recipients = 'name@abc.com',

    @body = 'This is test mail. See attached file',

    @query = @runquery,

    @query_attachment_filename = 'abc.xls',

    @query_result_header = 1,

    @subject = 'Test Report',

    @attach_query_result_as_file = 1,

    @query_result_no_padding = 1

  • @query_result_separator

    did you try this parameter?

  • add

    @query_result_separator = CHAR(9),

    and it works

  • Why not just force formatting as you need it to be

    SELECT CAST([Column1] AS VARCHAR(50)) + ',' + CAST([Column2] AS VARCHAR(50)) + ',' + CAST([Column3] AS VARCHAR(50))

    FROM [Database].[dbo].[Table]

    Will return Text1,Text2,Text3

  • Thanks

    Perfect solution are given .It working .So It very help for us your solution .

    Regards

    Saif

    Qazi Saif Hussain
    Mphasis, an hp company
    Pune India,
    saif.qazi0532@gmail.com:-)

Viewing 14 posts - 1 through 13 (of 13 total)

You must be logged in to reply to this topic. Login to reply