Seems like your servers and/or databases have different collations. Does this particular line of code represent a where clause that uses a #temp table? In 2008 R2 and earlier, #temp tables are created using the server collation rather than the calling database's collation. The same kind of issue will happen if you try to equate any two columns where the collation is different due to the server or database the column was created in.
Take a look at line 41, it should point to the columns that are causing the issue. You can trace them back and see that their collation_name
value is going to be different in sys.columns
(note that it sounds like they might be in different databases).
As you might guess, it is not trivial to change the server or database collation, however you can work around this by changing your where clauses as follows:
WHERE left_column COLLATE SQL_Latin1_General_CP437_CI_AI
= right_column COLLATE SQL_Latin1_General_CP437_CI_AI
This is not fun of course, and you can limit the collation specifiers to the columns that aren't using the local collation. I dealt for years with a system where one instance was set up as CP437 and the other two were set up as CP1. What a nightmare! Do you know if there's any reason why CP437 was in use?