What's the reason for the CAST conversion?
It seems like o.invoiceid is already a character data type. What exact data type are the two columns referenced in the join predicate (o.invoiceid and t.invoicedid)? What does the actual execution plan look like?