2017-02-09 76 views
-1

我有下面的代碼和我收到以下錯誤:排序規則衝突的非加入T-SQL代碼

Msg 468, Level 16, State 9, Line 37 
Cannot resolve the collation conflict between "SQL_Latin1_General_CP1_CI_AS" and "Latin1_General_CI_AS_KS_WS" in the equal to operation. 

我應該怎麼做才能解決這個問題?我在網上找到的所有東西都與連接的表格有關。

IF OBJECT_ID('SeanVault.dbo.TempVarIDs', 'U') IS NOT NULL 
     DROP TABLE SeanVault.dbo.TempVarIDs; 
    Select VariableID, VariableName 
    INTO SeanVault.dbo.TempVarIDs 
    from Variable 
      Where VariableName in (select VariableName from SeanVault.dbo.TempVarNames) 
+0

'如果VARIABLENAME中(選擇SeanVault.dbo.TempVarNames VARIABLENAME)COLLATE SQL_Latin1_General_CP1_CI_AS' – Lamak

+0

@Lamak爲什麼這是一個評論,而不是答案嗎? – iamdave

+0

@iamdave因爲代碼只有答案不是一個好答案......而且我有點累,所以我不想寫出什麼才能使它成爲一個好答案 – Lamak

回答

0

您的兩列VariableID和VariableNames具有不同的排序規則。您可以繞過整理配置(如果你不控制,例如你的數據模型),通過提供一個明確的歸類:

IF OBJECT_ID('SeanVault.dbo.TempVarIDs', 'U') IS NOT NULL 
    DROP TABLE SeanVault.dbo.TempVarIDs; 
Select VariableID, VariableName 
INTO SeanVault.dbo.TempVarIDs 
from Variable 
Where VariableName COLLATE SQL_Latin1_General_CP1_CI_AS in (select VariableName COLLATE SQL_Latin1_General_CP1_CI_AS from SeanVault.dbo.TempVarNames) 

一個長期的解決辦法是改變你列的定義,並添加所需的整理:

ALTER TABLE Variable 
     ALTER COLUMN VariableID COLLATE SQL_Latin1_General_CP1_CI_AS 
GO 

    ALTER TABLE TempVarNames 
     ALTER COLUMN TempVarNames COLLATE SQL_Latin1_General_CP1_CI_AS 
GO 
+0

完美!謝謝你的工作。這些表是臨時使用的表,並在程序運行後丟棄,所以我認爲我不會去ALTER路由。 – SeanDon