You can't use CAST without WHERE clause.

Then what are you doing with CAST?, the right parenthes is within CASE statements, that is not right. The CASE statement will return either Yes or No then what is the query supposed to do with that?.

The output of CASE in WHERE clause can be used for GROUP BY or to compare with something, you don't have that in the query.