Search code examples
sql-servert-sqltokenjobs

Msg 8169, Level 16, State 2, Line 3 Conversion failed when converting from a character string to uniqueidentifier. (when using a token)


I have this code in a job step, the stored procedure runs fine, the issue is with the getting of the job name.

declare @jobName varchar(100)

set @jobName = (select name from msdb..sysjobs where job_id = '$(ESCAPE_SQUOTE(JOBID))')

EXEC spSendSuccessEmail @jobName

Am I missing anything?

All I'm trying to do is pass the job id that the step is in to the stored procedure.


Solution

  • You are clearly using a varchar where a uniqueidentifier is expected. Ideally you want to fix the typing, but a cast will do the trick too. If the sp is expecting a uniqueidentifier try casting @jobName to uniqueidentifier before executing sp