SQL Result sent via email

Hi Experts,

I always check my LOGs via this command:

dbcc sqlperf(logspace)

The result should be sent via email.
Can you guide me how ?
Eprs_AdminSystem ArchitectAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David ToddSenior Database AdministratorCommented:
Hi,

Use sp_send_dbmail
https://msdn.microsoft.com/en-us/library/ms190307.aspx

Note that there are parameters for the query to run etc ...

Regards
  David
0
Eprs_AdminSystem ArchitectAuthor Commented:
Hi,

I am not sure if this sp is already installed on my sql.
With which command I can check all stored procedures ?
0
Eprs_AdminSystem ArchitectAuthor Commented:
When I copy this command, it is not working...

sp_send_dbmail [ [ @profile_name = ] 'profile_name' ]
    [ , [ @recipients = ] 'recipients [ ; ...n ]' ]
    [ , [ @copy_recipients = ] 'copy_recipient [ ; ...n ]' ]
    [ , [ @blind_copy_recipients = ] 'blind_copy_recipient [ ; ...n ]' ]
    [ , [ @from_address = ] 'from_address' ]
    [ , [ @reply_to = ] 'reply_to' ] 
    [ , [ @subject = ] 'subject' ] 
    [ , [ @body = ] 'body' ] 
    [ , [ @body_format = ] 'body_format' ]
    [ , [ @importance = ] 'importance' ]
    [ , [ @sensitivity = ] 'sensitivity' ]
    [ , [ @file_attachments = ] 'attachment [ ; ...n ]' ]
    [ , [ @query = ] 'query' ]
    [ , [ @execute_query_database = ] 'execute_query_database' ]
    [ , [ @attach_query_result_as_file = ] attach_query_result_as_file ]
    [ , [ @query_attachment_filename = ] query_attachment_filename ]
    [ , [ @query_result_header = ] query_result_header ]
    [ , [ @query_result_width = ] query_result_width ]
    [ , [ @query_result_separator = ] 'query_result_separator' ]
    [ , [ @exclude_query_output = ] exclude_query_output ]
    [ , [ @append_query_error = ] append_query_error ]
    [ , [ @query_no_truncate = ] query_no_truncate ] 
…………[ , [@query_result_no_padding = ] @query_result_no_padding ] 
    [ , [ @mailitem_id = ] mailitem_id ] [ OUTPUT ]

Open in new window

0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

David ToddSenior Database AdministratorCommented:
Hi,

The code you posted is the syntax - square brackets indicating optional elements, ellipsis indicating repeated elements etc.

You will need to edit this all to suit - see the examples further down the page ...

Regards
   David
0
Deepak ChauhanSQL Server DBACommented:
Please check the Database mail , sysmail account and sysmail profile is enabled on your system where you are running this SP if this is not configured you can not send the email.

You can check using below query.

select * from dbo.sysmail_account
select  * from dbo.sysmail_profile

if mail is configured on this system.
replace the parameter in below code and execute.

EXEC msdb.dbo.sp_send_dbmail
@profile_name = '<profilename>',
@recipients = '< receipent email address>',
@subject='<sublect line like Log Space or whatever>',
@query = '< tsql query here>',
@attach_query_result_as_file = 1
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Eprs_AdminSystem ArchitectAuthor Commented:
Hello,
how to find out, if the profile is created ?

@profile_name = '<profilename>',
0
Deepak ChauhanSQL Server DBACommented:
Hi,

Run this query in the ssms query window. it will show you profile name in the name column.

select * from msdb.dbo.sysmail_profile
0
Eprs_AdminSystem ArchitectAuthor Commented:
ok now it works -> thanks my friend
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.