以下T-SQL代码:
CREATE TABLE #exclude(name VARCHAR(256))
INSERT INTO #exclude VALUES('someprefix_someprocedure')
SELECT 'someschema.' + sys.objects.name
FROM sys.objects
LEFT JOIN #exclude ON sys.objects.name = #exclude.name
WHERE sys.objects.name LIKE 'someprefix_%'
AND type IN ('FN', 'TR', 'P')
AND #exclude.name IS NULL
ORDER BY sys.objects.name ASC
返回此错误:
消息468,级别16,状态9,第4行
无法在等于操作的情况下解决
Danish_Norwegian_CI_AS
和SQL_Latin1_General_CP1_CI_AS
之间的排序规则冲突。
我尝试将此附加到查询中,但它仍然返回相同的错误:
COLLATE SQL_Latin1_General_CP1_CI_AS ASC
我该如何解决这个问题?
答案 0 :(得分:1)
在WHERE或ON(JOIN)子句中将以下内容添加到产生此错误的任何字段:
COLLATE DATABASE_DEFAULT
。
e.g。 (你的问题)
CREATE TABLE #exclude(name VARCHAR(255))
INSERT INTO #exclude VALUES('someprefix_someprocedure')
SELECT 'someschema.' + sys.objects.name
FROM sys.objects
LEFT JOIN #exclude ON sys.objects.name COLLATE DATABASE_DEFAULT = #exclude.name COLLATE DATABASE_DEFAULT
WHERE sys.objects.name LIKE 'someprefix_%'
AND type IN ('FN', 'TR', 'P')
AND #exclude.name IS NULL
ORDER BY sys.objects.name ASC
答案 1 :(得分:0)
创建表格#exclude
时,您需要将COLLATE DATABASE_DEFAULT
添加到任何文本字段 - 如下所示:
CREATE TABLE #exclude(name VARCHAR(256) COLLATE DATABASE_DEFAULT NULL)
INSERT INTO #exclude VALUES('someprefix_someprocedure')
SELECT 'someschema.' + sys.objects.name
FROM sys.objects
LEFT JOIN #exclude ON sys.objects.name = #exclude.name
WHERE sys.objects.name LIKE 'someprefix_%'
AND type IN ('FN', 'TR', 'P')
AND #exclude.name IS NULL
ORDER BY sys.objects.name ASC