I'm running a query to change some returned data around in SQL Server 2016, and I am getting a conversion error (Conversion failed when converting date and/or time from character string).
SELECT jobs.name,
CASE WHEN jact.start_execution_date IS NULL THEN 'No Execution'
ELSE jact.start_exeuction_date
END AS start_execution_date
FROM msdb.dbo.sysjobactivity jact
INNER JOIN msdb.dbo.sysjobs jobs
ON jact.job_id = jobs.job_id
The start_execution_date column is a DATETIME type. This column either has a datetime format of (YYYY-MM-DD HH:MM:SS.mmm) or NULL in it. I even tried using COALESCE to make the code a little easier to read but that also did not work and gave the same error. When viewing the returned result set up to the point of the error, it is failing at the first row that has a NULL in this column. What am I doing wrong/not considering?
SELECT COALESCE(jact.start_execution_date, 'No Execution')