2014-01-21 62 views
1

Coudl請你告訴我wehre我應該把COLLATE DATABASE_DEFAULTSQL SERVER - 無法解析排序規則衝突的等於操作

獲得創建了以下看法?

我做了搜索,發現我應該把where子句放在每一邊。我嘗試了所有可能性,但仍得到同樣的錯誤,說'無法解決等於操作中「SQL_Latin1_General_CP1_CI_AS」和「Latin1_General_CI_AS」之間的排序規則衝突。

下面是該查詢:

CREATE view [dbo].[NewADUsers] AS SELECT 
tbl.objectGUID AS UserGUID 
, SUBSTRING(tbl.Email, CHARINDEX('@', tbl.Email)+1, 
LEN(tbl.Email)- CHARINDEX('@',tbl.Email)) AS 'DomainName' 
, gd.GroupName, dsg.DefaultSubGroup, tbl.sAMAccountName 
, tbl.sAMAccountName AS UserName, tbl.Email AS Email 
FROM (
SELECT 
"SAMAccountName" AS sAMAccountName, "mail" AS Email, "objectGUID" AS objectGUID 
    FROM OpenQuery(
     ADSI, 
     'SELECT SAMAccountName, mail, objectGUID 
     FROM ''LDAP://mydomain.com/OU=blah,OU=blah,OU=blah,DC=mydomain,DC=com'' 
     WHERE objectClass=''User''')) 
    AS tbl 
INNER JOIN dbo.GroupsDomains gd ON gd.DomainName = SUBSTRING(tbl.Email, CHARINDEX('@', tbl.Email)+1, LEN(tbl.Email)- CHARINDEX('@',tbl.Email)) 
LEFT JOIN dbo.DefaultSubGroups dsg ON gd.GroupName = dsg.GroupName 
WHERE tbl.objectGUID NOT IN (SELECT UserGUID FROM dbo.Users) 

GO

回答

1

我已經在這個問題上讀了多篇論文。最後我不明白這個錯誤是怎麼產生的。

我的解決辦法是:
將COLLATE DATABASE_DEFAULT聯接條件... ...

INNER JOIN dbo.GroupsDomains gd ON gd.DomainName = SUBSTRING(tbl.Email, CHARINDEX('@', tbl.Email)+1, 
LEN(tbl.Email)- CHARINDEX('@',tbl.Email)) 
LEFT JOIN dbo.DefaultSubGroups dsg 

-- Modified this next line: 
ON gd.GroupName COLLATE DATABASE_DEFAULT = dsg.GroupName COLLATE DATABASE_DEFAULT 

WHERE tbl.objectGUID NOT IN (SELECT UserGUID FROM dbo.Users) 
相關問題