Your second Case Expression
is a mix of Simple Case
and Searched Case
.
I.e.
CASE t.fstrType
WHEN '' THEN ''
WHEN (wd.fstrWorkType = 'SUSIN1'
Change it to a Searched Case
expression as:
CASE WHEN t.fstrType = '' THEN ''
WHEN (wd.fstrWorkType = 'SUSIN1' ...
Two formats of Case Expression are:
--Simple CASE expression:
CASE input_expression
WHEN when_expression THEN result_expression [ ...n ]
[ ELSE else_result_expression ]
END
--Searched CASE expression:
CASE
WHEN Boolean_expression THEN result_expression [ ...n ]
[ ELSE else_result_expression ]
END