how to send attached file in sql server 2008 using mail option

  • how to send attach file in sql server 2008 using sql mail option

  • http://msdn.microsoft.com/en-us/library/ms190307.aspx

    EXEC msdb.dbo.sp_send_dbmail

    @profile_name = 'AdventureWorks2008R2 Administrator',

    @recipients = 'danw@Adventure-Works.com',

    @query = 'SELECT COUNT(*) FROM AdventureWorks2008R2.Production.WorkOrder

    WHERE DueDate > ''2006-04-30''

    AND DATEDIFF(dd, ''2006-04-30'', DueDate) < 2' ,

    @subject = 'Work Order Count',

    @attach_query_result_as_file = 1 ;

    Also, if you search these forums, there are many examples of how to achieve what you are after!

    ________________________________________________________________________________

    Can I ask you a rhetorical question...?
    ________________________________________________________________________________

  • its using query but i need send csv file its stored in my disk

  • EXEC msdb.dbo.sp_send_dbmail

    @profile_name = 'Test',

    @recipients = 'xx@abc.com',

    @subject = 'Work Order Count',

    @file_attachments='R:\test\test.csv'

    its executing properly but mail is not come and when i execute without attachment parameter i'm geeting mail.

  • Is the R drive on the server (or machine) you are running the query from?

    Is it a network drive or share?

    ________________________________________________________________________________

    Can I ask you a rhetorical question...?
    ________________________________________________________________________________

  • Coolroof (7/1/2011)


    EXEC msdb.dbo.sp_send_dbmail

    @profile_name = 'Test',

    @recipients = 'xx@abc.com',

    @subject = 'Work Order Count',

    @file_attachments='R:\test\test.csv'

    its executing properly but mail is not come and when i execute without attachment parameter i'm geeting mail.

    Remember the sQL server you're writing this query against is the one sending the email. The R:\ drive on your computer may not be the same on on the SQL server. Unless the file is local to the SQL server, I typically use an UNC to the file instead to make sure I can get the attachment regardless.

    Keep in mind that the SQL Agent service account running on the SQL server must have access to the location and file in question as well. If your SQL agent is not a domain account, that will basically relegate you to only attaching files local to the SQL server.



    --Mark Tassin
    MCITP - SQL Server DBA
    Proud member of the Anti-RBAR alliance.
    For help with Performance click this link[/url]
    For tips on how to post your problems[/url]

  • And the size of attachment has limitation.....

  • how to use without using query parameter..

Viewing 8 posts - 1 through 7 (of 7 total)

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