SQL Server Agent Tokens
- Adam Thurgar
- May 25, 2019
- 1 min read
One of the good things about working with SQL Server is that you are constantly learning. It wasn't until very recently that I learnt about SQL Server Agent tokens. They are like environment variables that can be used within a job step. Books Online states as "Using tokens when you write your job steps gives you the same flexibility that variables provide when you write software programs. After you insert a token in a job step script, SQL Server Agent replaces the token at run time, before the job step is executed by the Transact-SQL subsystem."
For example: I found this very handy for writing job output to a file in the log directory using the SQLLOGDIR token.
$(ESCAPE_SQUOTE(SQLLOGDIR))\DatabaseBackup_$(ESCAPE_SQUOTE(JOBID))_$(ESCAPE_SQUOTE(STEPID))_$(ESCAPE_SQUOTE(STRTDT))_$(ESCAPE_SQUOTE(STRTTM)).txt
Read more
https://docs.microsoft.com/en-us/sql/ssms/agent/use-tokens-in-job-steps?view=sql-server-2017

Comments