Checking Bb SIS logs against current course IDs

SELECT * FROM [BBLEARN].[dbo].[data_intgr_log]
LEFT JOIN [BBLEARN].[dbo].[course_main] ON lower(rtrim(ltrim(RIGHT(
SUBSTRING([log_message], CHARINDEX('[',[log_message]), CHARINDEX(']',[log_message], CHARINDEX('[',[log_message])+1)-CHARINDEX('[',[log_message]))
, CHARINDEX(' ',
reverse(
SUBSTRING([log_message], CHARINDEX('[',[log_message]), CHARINDEX(']',[log_message], CHARINDEX('[',[log_message])+1)-CHARINDEX('[',[log_message]))
))
)))) = [course_main].lower_course_id

where data_intgr_pk1 = 2 and log_message like '%di.error.associate%' and [course_main].course_name is not null