• From the error, you're doing something with a string column, but without DDL for the tables and the CTE, anything I say would be a guess.