如何在 T-SQL 中正确构建整理命令?

发布于 2024-10-31 08:43:39 字数 1675 浏览 0 评论 0原文

我正在尝试编写跨两个链接服务器的查询。通过适当的登录设置链接后,我收到以下整理错误:

无法解决排序规则冲突 在“SQL_Latin1_General_CP1_CI_AS”之间 和“Latin1_General_CI_AS”中 等于操作。

这对我来说是新的,但它看起来像是字符集冲突,所以我用谷歌搜索它并发现了可以添加到我的联接中的整理命令。不过我已经尝试过

va ON V_ID1 = c1.strData COLLATE Latin1_General_CI_AS

va ON V_ID1 = c1.strData COLLATE SQL_Latin1_General_CP1_CI_AS

并且似乎都没有解决该错误。我做错了什么?

编辑:整个查询太大,无法发布并期望人们进行过滤,但这是相关的部分:

   select
        rel.intParentAttributeId as intItemId,
        case va.type
        when 'SM' then 120000000
        when 'FB' then 110000000
        when 'RO' then 100000000
        when 'SP' then 90000000
        when 'A' then 80000000
        when 'D' then 70000000
        when 'P' then 60000000
        when 'SR' then 50000000
        when 'FN' then 40000000
        when 'RL' then 30000000
        when 'VO' then 20000000
        when 'RE' then 10000000
        end
        +

        rel.intParentAttributeId
        as fltStrength
        from
        AttributeMap ky

        join Catalogue c1 on c1.intRowId=ky.intChildAttributeId and c1.intAttributeTypeId=@intsimilarAtt

        join

        [SQLSERVERNAME].[SchemaName].dbo.VidAssc
         va on V_ID1 COLLATE SQL_Latin1_General_CP1_CI_AS = c1.strData COLLATE SQL_Latin1_General_CP1_CI_AS


        join Catalogue c2 on c2.strData=V_ID2 and c2.intAttributeTypeId=@intsimilarAtt

        join AttributeMap rel on rel.intChildAttributeId = c2.intRowId

        join @tmpSeeds s on s.intItemId = ky.intParentAttributeId

        group by rel.intParentAttributeId,va.Type

        )sqi

干杯, 马特

I'm trying to write a query across two linked servers. Having set up the link with an appropriate logon, I'm getting this collate error:

Cannot resolve the collation conflict
between "SQL_Latin1_General_CP1_CI_AS"
and "Latin1_General_CI_AS" in the
equal to operation.

This is new to me, but it looks like a charset conflict, so I googled it and discovered the collate command which can be added to my join. However I've tried both

va ON V_ID1 = c1.strData COLLATE Latin1_General_CI_AS

and

va ON V_ID1 = c1.strData COLLATE SQL_Latin1_General_CP1_CI_AS

And neither seems to resolve the error. What am I doing wrong?

EDIT: The entire query is too big to post and expect people to filter through, but here's the relevant bit:

   select
        rel.intParentAttributeId as intItemId,
        case va.type
        when 'SM' then 120000000
        when 'FB' then 110000000
        when 'RO' then 100000000
        when 'SP' then 90000000
        when 'A' then 80000000
        when 'D' then 70000000
        when 'P' then 60000000
        when 'SR' then 50000000
        when 'FN' then 40000000
        when 'RL' then 30000000
        when 'VO' then 20000000
        when 'RE' then 10000000
        end
        +

        rel.intParentAttributeId
        as fltStrength
        from
        AttributeMap ky

        join Catalogue c1 on c1.intRowId=ky.intChildAttributeId and c1.intAttributeTypeId=@intsimilarAtt

        join

        [SQLSERVERNAME].[SchemaName].dbo.VidAssc
         va on V_ID1 COLLATE SQL_Latin1_General_CP1_CI_AS = c1.strData COLLATE SQL_Latin1_General_CP1_CI_AS


        join Catalogue c2 on c2.strData=V_ID2 and c2.intAttributeTypeId=@intsimilarAtt

        join AttributeMap rel on rel.intChildAttributeId = c2.intRowId

        join @tmpSeeds s on s.intItemId = ky.intParentAttributeId

        group by rel.intParentAttributeId,va.Type

        )sqi

Cheers,
Matt

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无边思念无边月 2024-11-07 08:43:39

尝试将 COLLATE 也放在左侧:

FROM Table1 AS t1
INNER JOIN Table2 AS t2
 ON t1.ID COLLATE Latin1_General_CI_AS
  = t2.ID --COLLATE Latin1_General_CI_AS --optionally on the right if needed.

Try putting the COLLATE on the left side as well:

FROM Table1 AS t1
INNER JOIN Table2 AS t2
 ON t1.ID COLLATE Latin1_General_CI_AS
  = t2.ID --COLLATE Latin1_General_CI_AS --optionally on the right if needed.
回忆追雨的时光 2024-11-07 08:43:39

好吧,终于找到解决方法了。这是你必须做的:

在 sql server manager 中到 Server Objects >链接服务器>并找到有问题的链接服务器。

右键单击> 服务器选项下的属性

将“使用远程排序规则”设置为“False”
和“排序规则名称”为“Latin1_General_CI_AS”

OK, finally found a fix. Here's what you have to do:

In sql server manager to to Server Objects > Linked Servers > and find the problematic linked server.

Right Click > Properties

Under Server Options set "Use Remote Collation" to "False"
and "Collation Name" to "Latin1_General_CI_AS"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文