gpt4 book ai didi

sql-server - 无法解决 SELECT 语句中第 4 列的排序规则冲突

转载 作者:行者123 更新时间:2023-12-04 00:07:23 48 4
gpt4 key购买 nike

我正在尝试执行一些 SQL,但出现以下错误

    Msg 451, Level 16, State 1, Line 1
Cannot resolve collation conflict for column 4 in SELECT statement.

但似乎无法弄清楚问题出在哪里???非常感谢任何帮助。

SELECT     MEMBTYPEID.text AS MemberType, MEMBLST.nodeId, MEMBTYPES.Name AS MemberField, 
ISNULL(CASE WHEN MEMBTYPES.datatypeID IN
(SELECT NodeId
FROM DBO.CMSDATATYPE
WHERE DBTYPE = 'Nvarchar') THEN MEMBDATA.[dataNvarchar] WHEN MEMBTYPES.datatypeID IN
(SELECT NodeId
FROM DBO.CMSDATATYPE
WHERE DBTYPE = 'Ntext') THEN MEMBDATA.[dataNtext] WHEN MEMBTYPES.datatypeID IN
(SELECT NodeId
FROM DBO.CMSDATATYPE
WHERE DBTYPE = 'Date') THEN CONVERT(NVARCHAR, MEMBDATA.[dataDate]) WHEN MEMBTYPES.datatypeID IN
(SELECT NodeId
FROM DBO.CMSDATATYPE
WHERE DBTYPE = 'Integer') THEN CASE WHEN
(SELECT value
FROM [dbo].[cmsDataTypePreValues]
WHERE datatypenodeid = MEMBTYPES.[dataTypeId] AND id = CONVERT(INT, MEMBDATA.[dataInt])) IS NOT NULL THEN
(SELECT value
FROM [dbo].[cmsDataTypePreValues]
WHERE datatypenodeid = MEMBTYPES.[dataTypeId] AND id = CONVERT(INT, MEMBDATA.[dataInt])) ELSE CONVERT(NVARCHAR,
MEMBDATA.[dataInt]) END ELSE NULL END, '') AS MemberData
FROM (SELECT id, text
FROM dbo.umbracoNode
WHERE (nodeObjectType = '9b5416fb-e72f-45a9-a07b-5a9a2709ce43')) AS MEMBTYPEID LEFT OUTER JOIN
(SELECT nodeId, contentType
FROM dbo.cmsContent) AS MEMBLST ON MEMBLST.contentType = MEMBTYPEID.id LEFT OUTER JOIN
dbo.cmsPropertyType AS MEMBTYPES ON MEMBTYPES.contentTypeId = MEMBLST.contentType LEFT OUTER JOIN
dbo.cmsPropertyData AS MEMBDATA ON MEMBDATA.contentNodeId = MEMBLST.nodeId AND
MEMBDATA.propertytypeid = MEMBTYPES.id LEFT OUTER JOIN
dbo.cmsMember AS MEMB ON MEMB.nodeId = MEMBLST.nodeId
WHERE (MEMBLST.nodeId IS NOT NULL)

我的SQL技能很基础,所以希望有人能帮忙

~~~~~~~~~~~~工作代码~~~~~~~~~~~~~

设法让它工作,这是代码

SELECT MEMBTYPEID.text AS MemberType, MEMBLST.nodeId, MEMBTYPES.Name AS MemberField, MEMBTYPES.Alias AS MemberFieldAlias, MEMB.LoginName,
ISNULL(CASE
WHEN MEMBTYPES.datatypeID IN (SELECT NodeId FROM DBO.CMSDATATYPE WHERE DBTYPE = 'Nvarchar') THEN MEMBDATA.[dataNvarchar]
WHEN MEMBTYPES.datatypeID IN (SELECT NodeId FROM DBO.CMSDATATYPE WHERE DBTYPE = 'Ntext') THEN MEMBDATA.[dataNtext]
WHEN MEMBTYPES.datatypeID IN (SELECT NodeId FROM DBO.CMSDATATYPE WHERE DBTYPE = 'Date') THEN CONVERT(NVARCHAR, MEMBDATA.[dataDate])
WHEN MEMBTYPES.datatypeID IN (SELECT NodeId FROM DBO.CMSDATATYPE WHERE DBTYPE = 'Integer') THEN CONVERT(NVARCHAR, MEMBDATA.[dataInt])
ELSE NULL END, NULL)
AS MemberData
FROM
(SELECT id, text FROM dbo.umbracoNode WHERE (nodeObjectType = '9b5416fb-e72f-45a9-a07b-5a9a2709ce43')) AS MEMBTYPEID
LEFT OUTER JOIN (SELECT nodeId, contentType FROM dbo.cmsContent) AS MEMBLST ON MEMBLST.contentType = MEMBTYPEID.id
LEFT OUTER JOIN dbo.cmsPropertyType AS MEMBTYPES ON MEMBTYPES.contentTypeId = MEMBLST.contentType
LEFT OUTER JOIN dbo.cmsPropertyData AS MEMBDATA ON MEMBDATA.contentNodeId = MEMBLST.nodeId AND MEMBDATA.propertytypeid = MEMBTYPES.id
LEFT OUTER JOIN dbo.cmsMember AS MEMB ON MEMB.nodeId = MEMBLST.nodeId
WHERE (MEMBLST.nodeId IS NOT NULL)

最佳答案

排序规则基本上是一个代码页,告诉 sql 如何解释/比较/排序字符串。例如,它可以区分大小写或(不)忽略重音符号(如法语中的 ^)。更多信息,see here .

在 sql server 中,您可以在服务器/数据库/列级别上设置排序规则,其中每个较低级别都可以覆盖较高级别的默认值。这使您可以比较来自两个不同排序规则的字符串。这就是问题所在。有时不可能比较 2 个不同的归类。例如,如果第 1 列的排序规则不区分大小写,而第 2 列区分大小写,并且您将第 1 列的“AAA”与第 2 列的“aaa”进行比较,它们是否相等?在这种情况下,sql 会抛出一个排序错误。

column 4 指的是您的 MemberData 列,即巨大的 ISNULL(Case ... 语句。Sql 归类冲突通常发生在字符串之间的比较中,因此这意味着您的其中一个IN or = 运算符是罪魁祸首。为了调试,我会逐渐删除该语句的部分,直到错误不再发生。然后检查刚刚删除的部分中列的排序规则。如果它们不同,则很可能那是你的问题。

然后你可以使用 COLLATE强制将其中一列的字符串强制转换为另一列的排序规则。但是请注意,根据您的排序规则,您可能会得到奇怪的比较结果,即 'Â' 可以等于或不等于 'a'。我会尝试确定您的列中的哪些字符串给出了排序规则错误,以便您可以看到使用 COLLATE 会产生什么影响。

作为一般规则,我建议永远不要为了防止这种麻烦而覆盖数据库的默认排序规则。

关于sql-server - 无法解决 SELECT 语句中第 4 列的排序规则冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5026553/

48 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com