Database Mail - Multiple queries within sp_send_dbmail.

Posted on 2010-01-07
1 Endorsement
Last Modified: 2012-05-08
Hi guys,

I was wondering if anyone had any luck running multiple queries within sp_send_dbmail.

What I would like to do is either :
1. Attach more than 1 attachment, each being the result of different queries ,or
2. Attach these results in different sheets within my excel attachment that is being sent via sp_send_dbmail.

Thanks for you assistance.


Question by:CrispyC4
    LVL 13

    Accepted Solution

    sp_send_dbmail accepts only 1 sql query parameter.
    For more complex requierments, you can try using the SSIS packages to run mulitple queries and generate multiple files (1 file multiple sheets).. and then send them using the send mail task


    Author Comment

    Thanks Wizilling

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
    In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

    730 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

    16 Experts available now in Live!

    Get 1:1 Help Now