How to convert a variable to be used in where clause I have stored Job_id value of msdb..sysjob in a variable @job_id_char, which i want to use against msdb..sysjobactivity to get the 'start_execution_date' value.
I have used following query but getting error as conversion failed

select start_execution_date from msdb.dbo.sysjobactivity where job_id = @job_id_char


I know that i have to convert the variable, but i don't know how
Since the data type of the job_id in the msdb.dbo.sysjob table is uniqueidentifier.

So you need to create the @job_id_char as a uniqueidentifier variable, like
DECLARE @job_id_char uniqueidentifier
then only it can be used in the WHERE clause of msdb.dbo.sysjobactivity table.

Or you can JOIN the tables by the the job_id like 

SELECT sja.start_execution_date, .....
FROM msdb.dbo.sysjobs sj
JOIN msdb.dbo.sysjobactivity sja ON sj.job_id = sja.job_id
WHERE ..... -- condition related sysjobs tables