[SQL Server] 如何 join 不同 Codec 的 tables

利用SQL statement做Report時, join table 是無可避免的. 但如果join 不同database 的 table 時, 有機會出現錯誤信息如下:

Msg 468, Level 16, State 9, Line 11
Cannot resolve the collation conflict between “Chinese_Taiwan_Bopomofo_BIN” and “Chinese_Hong_Kong_Stroke_90_CI_AS” in the equal to operation.

這是因為不同 database 的collate setting 不同而令join table 時出現問題. 若想知道自己database, 可以於SSMS 中的database 中右鍵 > Properties, 在General 中會見到其相對應的 Collate.

要解決的話, 最直接的方法就是在join table 時加入 COLLATE database_default, 使SQL server join table 預設用預設的collate. 用法如下:

SELECT User.*
FROM User U, [RemoteDatabase].[Authorization].dbo.Privilege P
WHERE U.UserID=P.UserID COLLATE Database_Default
;

 

About C.H. Ling 260 Articles
a .net / Java developer from Hong Kong and currently located in United Kingdom. Thanks for Google because it solve many technical problems so I build this blog as return. Besides coding and trying advance technology, hiking and traveling is other favorite to me, so I will write down something what I see and what I feel during it. Happy reading!!!

Be the first to comment

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.