• You need to break down your code into sections. Work through each part, 1 at a time to work out the issue.

    Your CASE statement has your t. & t4. aliases, but no FROM part and not of the joins and aliases.

    So either use variables, set them in your select statement then update using them, or put your code directly in the update statement.