How to fix a collation conflict in a SQL Server query?

后端 未结 5 1965
故里飘歌
故里飘歌 2020-12-09 00:53

I am working on a view, wherein I am using an inner join on two tables which are from two different servers. We are using linked server. When running the query I am getting

5条回答
  •  难免孤独
    2020-12-09 01:43

    Adding to the accepted answer, you can used DATABASE_DEFAULT as encoding.

    This allows database to make choice for you and your code becomes more portable.

    SELECT MyColumn
    FROM 
        FirstTable a
            INNER JOIN SecondTable b
                ON a.MyID COLLATE DATABASE_DEFAULT = b.YourID COLLATE DATABASE_DEFAULT
    

提交回复
热议问题