July 1, 2011 at 7:56 am
how to send attach file in sql server 2008 using sql mail option
July 1, 2011 at 8:43 am
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...?
________________________________________________________________________________
July 1, 2011 at 8:45 am
its using query but i need send csv file its stored in my disk
July 1, 2011 at 8:55 am
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.
July 1, 2011 at 9:13 am
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...?
________________________________________________________________________________
July 1, 2011 at 9:16 am
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.
July 1, 2011 at 10:15 am
And the size of attachment has limitation.....
July 1, 2011 at 9:50 pm
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