Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin.
Search for scripts directly from SSMS, and instantly access any saved scripts in your
SSC briefcase from the favorites tab.
Download now (direct download link)
Thank this author by sharing:
By Dave Gugg,
This script will create a stored procedure that can be used to send dbMail with query results in an html table. For ease of use I've broken the query parts out into separate parameters. The list of fields being returned should be delimited using the pipe character |.
There are other sources that explain how to include query results as an html table. The focus of this script is to create a stored procedure that is easy to use. The stored procedure is also set up to not send emails if no results are returned from the query. Note that all objects must be fully qualified (database.schema.object) and parts of the query that are not needed are optional.
A sample call would be:
FTP the results from a stored procedure query
Query results splitter
Copy query result issue
Query result out of......
Creating view from stored procedure results