I have a SQL Job
where I want to send an email alert if job fails. I know that for this functionalty I have to Configure Database Mail
and than Adjust the properties within the SQL Server Agent
. This article gives pretty good detail http://www.sherweb.com/blog/how-to-set-up-database-mail-for-sql-server-job-failures/.
What I want is, instead of setting up an email address to particular user like person1@test.com
, I want to send an email to current user. This way who ever logged in to database and runs the job receives the email on job failure.
As I see, there are two benefits of this approach, i. One particular user won't get flooded with emails. ii. Who ever is running the job can know that job has failed.
For example,
If I set person1@test.com
and person2 logs in than on job failure person1 will receive an email. I don't want that. Is there any way that I can do this in SQL Server Agent Job
settings. If no than how can I achieve this?
Like SELECT SYSTEM_USER
or SELECT SUSER_NAME()
gives me current user and use that as outgoing email address.