Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Basically, you can use DBMail, if that's your preferred method of sending e-mail from within SQL server. Here's <a href="https://stackoverflow.com/questions/1322281/sp-send-dbmail-will-not-send-query-results">another thread</a> that shows you an example and talking about limitation of sending query results via that method.</p> <p>So, add this to your scheduled job and you should get desired results.</p> <p>Here's how to control the query output and placement in the e-mail <a href="http://msdn.microsoft.com/en-us/library/ms190307.aspx" rel="nofollow noreferrer">straight from MSDN</a> if you want to use CSV or similar:</p> <blockquote> <p>[ <strong>@attach_query_result_as_file=</strong> ] attach_query_result_as_file Specifies whether the result set of the query is returned as an attached file. attach_query_result_as_file is of type bit, with a default of 0.</p> <p>When the value is 0, the query results are included in the body of the e-mail message, after the contents of the @body parameter. When the value is 1, the results are returned as an attachment. This parameter is only applicable if @query is specified.</p> <p>[ <strong>@query_attachment_filename</strong>= ] query_attachment_filename Specifies the file name to use for the result set of the query attachment. query_attachment_filename is of type nvarchar(255), with a default of NULL. This parameter is ignored when attach_query_result is 0. When attach_query_result is 1 and this parameter is NULL, Database Mail creates an arbitrary filename.</p> <p>[ <strong>@query_result_header</strong>= ] query_result_header Specifies whether the query results include column headers. The query_result_header value is of type bit. When the value is 1, query results contain column headers. When the value is 0, query results do not include column headers. This parameter defaults to 1. This parameter is only applicable if @query is specified.</p> <p>[ <strong>@query_result_width</strong> = ] query_result_width Is the line width, in characters, to use for formatting the results of the query. The query_result_width is of type int, with a default of 256. The value provided must be between 10 and 32767. This parameter is only applicable if @query is specified.</p> <p>[ <strong>@query_result_separator</strong>= ] 'query_result_separator' Is the character used to separate columns in the query output. The separator is of type char(1). Defaults to ' ' (space).</p> </blockquote> <p>If you want to use XML, you just have to make sure your query returns XML. Otherwise, you'd have to write a procedure to format tabular query as XML. </p> <p><a href="http://www.sqlservercentral.com/articles/Integration+Services+%28SSIS%29/62678/Printable" rel="nofollow noreferrer">Here's another route</a> using SSIS, but it's more involved, but gives you more control over the output and formatting.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload