• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 300
  • Last Modified:

Send SQL Email With Attachment (Location in Path Field)

I have a table that stores the location of a document (Documents) and another that stores the email address (engineers).  I want to know if it's possible to send an email from sql with an attachment?
0
Lapchien
Asked:
Lapchien
1 Solution
 
LapchienDirectorAuthor Commented:
Thanks, so I have the following code, it only outputs the first record, how can I get it to skip through all the records and send multiple emails out?




DECLARE
	@EmailAddress varchar(255),
	@Attachments varchar(255)

SELECT
	@EmailAddress = Engineers.EmailAddress, 
	@Attachments = [Path]
FROM 
	TASDocument
	inner join Documents on Documents.DocId = TASDocument.DocId
	inner join Engineers on Engineers.EngineerId = TASDocument.EngineerId

where Documents.DocTypeId = 50
and Documents.PayBatchNo = 'PB0047'



EXEC msdb.dbo.sp_send_dbmail
@recipients='@EmailAddress',
@body='Message Body', 
@subject ='Message Subject',
@profile_name ='Administrator',
@file_attachments=@Attachments;

Open in new window

0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now