请告诉我,我应该放COLLATE DATABASE_DEFAULT
创建以下视图?
我做了搜索,发现我应该把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
答案 0 :(得分: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)