Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 Script Library
 How to get current jobname

Author  Topic 

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-10-13 : 04:30:39
Put this code in a step of the job you dynamically want to know the name of
DECLARE	@SQL NVARCHAR(72),
@jobID UNIQUEIDENTIFIER,
@jobName SYSNAME

SET @SQL = 'SET @guid = CAST(' + SUBSTRING(APP_NAME(), 30, 34) + ' AS UNIQUEIDENTIFIER)'

EXEC sp_executesql @SQL, N'@guid UNIQUEIDENTIFIER OUT', @guid = @jobID OUT

SELECT @jobName = name
FROM msdb..sysjobs
WHERE job_id = @jobID


E 12°55'05.63"
N 56°04'39.26"
   

- Advertisement -