Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

job token Expand / Collapse
Author
Message
Posted Tuesday, February 5, 2013 2:35 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, June 26, 2014 1:17 AM
Points: 90, Visits: 239
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
Post #1415659
Posted Tuesday, February 5, 2013 5:55 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Saturday, August 23, 2014 8:34 AM
Points: 7,097, Visits: 12,601
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:

Using Tokens in Job Steps


__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Post #1415776
Posted Tuesday, February 5, 2013 6:19 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, June 26, 2014 1:17 AM
Points: 90, Visits: 239
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

Post #1415791
Posted Tuesday, February 5, 2013 6:25 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Saturday, August 23, 2014 8:34 AM
Points: 7,097, Visits: 12,601
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
Post #1415797
Posted Tuesday, February 5, 2013 6:42 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, June 26, 2014 1:17 AM
Points: 90, Visits: 239
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
Post #1415804
Posted Tuesday, February 5, 2013 7:02 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Saturday, August 23, 2014 8:34 AM
Points: 7,097, Visits: 12,601
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
Post #1415815
Posted Tuesday, February 5, 2013 7:14 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, June 26, 2014 1:17 AM
Points: 90, Visits: 239
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
Post #1415821
Posted Tuesday, February 5, 2013 7:19 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Saturday, August 23, 2014 8:34 AM
Points: 7,097, Visits: 12,601
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
Post #1415825
Posted Tuesday, February 5, 2013 7:22 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, June 26, 2014 1:17 AM
Points: 90, Visits: 239

but the out file doesnt show the database name , which is used in token
Post #1415831
Posted Tuesday, February 5, 2013 7:36 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, June 26, 2014 1:17 AM
Points: 90, Visits: 239
Thanks

is job token must be runned by alert or it can be runned as normal job

Thanks
Post #1415837
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse