At time, you might need to report the actual SQL Agent job name that took the action in your notification. For example, you have a SQL Agent job that send user an email notification and you want to include in the notification the actual job name that sends the notification. You might hardcode the job name in the notification. However, when the job renamed, you need to also remember to update the hardcoded job name in the code as well. You can use following code to get the actual job name at run time inside your code without hardcoding.
SELECT
name
FROM
msdb.dbo.sysjobs
WHERE
job_id = $(ESCAPE_SQUOTE(JOBID))
~~~
FEATURED TAGS
ai
api
automation
azure
azure cosmos db
azure openai
azure vm
base64
dax
docker
excel
execution plan
hyper-v
infrastructure
m
machine learning
machine learning services
network
network card
performance
power automate
power bi
power bi report tricks
power query
powershell
python
qgis
query performance
regex
replication
snowflake
sql
sql script
sql server
sql server admin
sql server config
ssl
ssms
troubleshooting
unicode
vmware