-
Email Script to Attach Query Results
Hello,
I'm trying to run a script that is going to pul data from my table in my production database I can't figure out how to set this up I'm using a temporary one for now its sending me results from what is in the script. Can anyone help me find a solution.
DECLARE @sub VARCHAR(100)
DECLARE @qry VARCHAR(1000)
DECLARE @msg VARCHAR(250)
DECLARE @query NVARCHAR(1000)
DECLARE @query_attachment_filename NVARCHAR(520)
SELECT @sub = 'TEST XML ATTACHMENT'
SELECT @msg = 'This is Just a test.'
SELECT @query = ' SET NOCOUNT ON;
Select top 10 * from master..sysobjects WITH(NOLOCK) '
SELECT @query_attachment_filename = 'test.csv'
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'WESA DC Weekly ',
@recipients = 'edward.vahovick@gimi.org',
@copy_recipients = 'edward.vahovick@gimi.org',
@body = @msg,
@subject = @sub,
@query = @query,
@query_attachment_filename = @query_attachment_filename,
@attach_query_result_as_file = 1,
@query_result_header = 1,
@query_result_width = 256 ,
@query_result_separator = ' ' ,
@query_result_no_padding =1;
exec msdb.dbo.sysmail_start_sp
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|