February 5, 2013 at 2:35 am
Dear Experts
How to use token in sql agent job or alert to send data to operator about alert like database name for example.
Thanks lot
February 5, 2013 at 5:55 am
Without more detailed information about what you are trying to do and what you have tried so far all I can do is refer you to Books Online:
There are no special teachers of virtue, because virtue is taught by the whole community.
--Plato
February 5, 2013 at 6:19 am
Thanks for replying
I have read these info, but I need to know where should I write the token
should I write it inside the job after the t-sql code step or in a seperate step or where.
Thanks lot
February 5, 2013 at 6:25 am
Tokens are to be embedded within the job step command text. They are replaced at runtime with the value pointed to by the token.
From Example A in the article I linked to:
PRINT N'Current database name is $(A-DBN)' ;
Put the above text into a T-SQL Job Step and run the job. Look at the job history. Then open the job and change text to:
USE msdb;
PRINT N'Current database name is $(A-DBN)' ;
Now run the job again and check the job history.
There are no special teachers of virtue, because virtue is taught by the whole community.
--Plato
February 5, 2013 at 6:42 am
Thanks for replying
I wrote PRINT N'Current database name is $(ESCAPE_SQUOTE(A-DBN))' ;
inside step, and the job is succeded, and the mail alert has sent by the operator to the target email
but nothing is changed, I mean the token should send in the mail the database name but it doesnt
what do you suggest
Thanks
February 5, 2013 at 7:02 am
I think you are misunderstanding. The token in the print statement will not affect the Alert email, only the output of the job step itself. If you want to send a custom email alert then call msdb.dbo.sp_send_dbmail from the job step directly. The Alert emails from Agent Jobs are not customizable.
There are no special teachers of virtue, because virtue is taught by the whole community.
--Plato
February 5, 2013 at 7:14 am
Thanks
I made an output file to the step, but what is writen is
Job 'testbackup' : Step 1, 'token1' : Began Executing 2013-02-05 16:12:34
Current database name is [SQLSTATE 01000]
any suggestion
February 5, 2013 at 7:19 am
Yes. Keep experimenting until you learn them. Tokens do work, I use them all the time.
There are no special teachers of virtue, because virtue is taught by the whole community.
--Plato
February 5, 2013 at 7:22 am
but the out file doesnt show the database name , which is used in token
February 5, 2013 at 7:36 am
Thanks
is job token must be runned by alert or it can be runned as normal job
Thanks
February 5, 2013 at 7:50 am
The A in A-DBN is for Alerts. If you simply want the DB Name in the output of a standard job why would you need a token? :Whistling:
You would just do something like this:
PRINT N'Database name is ' + DB_NAME()
There are no special teachers of virtue, because virtue is taught by the whole community.
--Plato
February 5, 2013 at 8:07 am
Thanks
Then Hoe do you suggest to use token appropriatly or better usages
Thanks
February 5, 2013 at 9:42 am
If you could clarify your original post about what you are trying to do...
There are no special teachers of virtue, because virtue is taught by the whole community.
--Plato
February 5, 2013 at 10:18 am
Thanks
I am just trying to understand and test how to use token, if you have more information about usages this will be helpful
Thanks lot
February 5, 2013 at 10:32 am
To test the A- tokens, in a test environment of course:
- Setup a job that has the PRINT statement from Example A from the article I posted earlier.
PRINT N'Current database name is $(ESCAPE_SQUOTE(A-DBN))' ;
- Setup an Alert that fires for Database Errors with Severity 16 that starts the job you just created.
- Run this in a Query window which should prompt the job to execute, per the Alert:
RAISERROR('hi',16,1) WITH LOG;
- Check the job history to make sure it ran and check the step history to see the output of the PRINT statement.
- Now change databases and raise the error again.
- Again check the job history to make sure it ran and check the step history to see the output of the PRINT statement has changed to show the new database context.
There are no special teachers of virtue, because virtue is taught by the whole community.
--Plato
Viewing 15 posts - 1 through 15 (of 16 total)
You must be logged in to reply to this topic. Login to reply