Send SQL Email With Attachment (Location in Path Field)

Posted on 2011-10-21
Last Modified: 2012-05-12
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?
Question by:Lapchien
    LVL 22

    Accepted Solution


    Author Comment

    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?

    	@EmailAddress varchar(255),
    	@Attachments varchar(255)
    	@EmailAddress = Engineers.EmailAddress, 
    	@Attachments = [Path]
    	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
    @body='Message Body', 
    @subject ='Message Subject',
    @profile_name ='Administrator',

    Open in new window


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    After restoring a Microsoft SQL Server database (.bak) from backup or attaching .mdf file, you may run into "Error '15023' User or role already exists in the current database" when you use the "User Mapping" SQL Management Studio functionality to al…
    SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
    This video discusses moving either the default database or any database to a new volume.
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now