Executing SQL Script in Database shown in Alert

by Feb 4, 2015

How do I configure a Alert Response to execute a SQL Script in the database identified in an alert? Specifically, I have a script that I want to execute when I receive the Table Fragmentation > 75% alert. I know the Alert Response is firing since I tagged on specific wording in the email and I see the SQL Script getting executed but it is in the Master database. I tried using the $(Database) variable in my script but it errors out when testing the alert. Any ideas?