The clause:
AND CAST(SUBSTRING(CONVERT(VARCHAR(10),h.run_date) , 5,2) +'-'
+ SUBSTRING(CONVERT(VARCHAR(10),h.run_date) , 7,2) +'-'
+ SUBSTRING(CONVERT(VARCHAR(10),h.run_date),1,4) AS SMALLDATETIME) = CONVERT(VARCHAR(10), GETDATE(), 121)
is destined to scan the entire sysjobhistory table.
For small sysjobhistory row counts, that...