
利用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 ;
Leave a Reply