I am trying to build a case/if statement in a JOIN ON
clause.
LEFT JOIN [CTSTRC] [Statuses] ON RIGHT([Statuses].[STRID], 3) = [CTE].[F61]
Wouldn't something like this work:
LEFT JOIN [CTSTRC] [Statuses] ON RIGHT([Statuses].[STRID], 3) = cast([CTE].[F61] as varchar(3))
All you really care about is whether you have a match, so why not convert the numeric to varchar? You would have to test both ideas to see which one is faster.
I do agree with @KM, fixing a bad design like this is the best solution. Having functions and Case statements in a join is an indicatior that your design is fatally flawed and should be fixed.