简体   繁体   English

SQL Server 2005日期比较-排序规则问题

[英]SQL Server 2005 date comparison - collation issues

In my DB, I have a table that was created from an Excel sheet, via a Linked Server option. 在我的数据库中,我有一个通过链接服务器选项从Excel工作表创建的表。

I am now trying to compare its contents versus one of my main tables. 我现在正尝试将其内容与我的主表之一进行比较。

The tables I am comparing are in the same database. 我正在比较的表在同一数据库中。

There is a date column in both tables, both types are datetime and have Collation of SQL_Latin1_General_CP1_CI_AS, the same as the DB. 两个表中都有一个日期列,两种类型均为日期时间,并且具有SQL_Latin1_General_CP1_CI_AS的归类,与数据库相同。

The server collation is Latin1_General_CI_AS 服务器排序规则为Latin1_General_CI_AS

However when I try to run a query comparing the dates between the tables, I get the error: 但是,当我尝试运行查询以比较表之间的日期时,出现错误:

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

I have tried with and without the COLLATE option, using both collation settings. 我尝试使用和不使用COLLATE选项,同时使用两种排序规则设置。

My query is: 我的查询是:

select * , hxl.holiday_dt, 
datediff(d, h.holiday_dt collate SQL_Latin1_General_CP1_CI_AS, 
            hxl.holiday_dt collate SQL_Latin1_General_CP1_CI_AS)
from holiday h, Holiday_XL hxl
where h.currency_cd=hxl.currency_cd

In fact any query involving both tables gives exactly the same collation error, eg this one: 实际上,任何涉及这两个表的查询都会给出完全相同的排序规则错误,例如:

select count(*)
from Holiday_XL c
where c.currency_cd in (select distinct h.currency_cd from holiday h)

Thanks in advance for any thoughts. 预先感谢您的任何想法。

Regards, Chris 克里斯,问候

The error is being reported on the currency comparison h.currency_cd=hxl.currency_cd , not on datediff, so try force collation on the currencies. 该错误是在货币比较h.currency_cd = hxl.currency_cd上报告的 ,而不是在datediff上报告的,因此请尝试对货币强制校对。

Collation is only relevant for character (char, varchar, nvarchar) and text types. 排序规则仅与字符(char,varchar,nvarchar)和文本类型相关。

Under the Collation and give the collation table level there are lot of tips and code available in net search with topic of collation. 在归类并提供归类表级别下,可以在带有归类主题的网络搜索中找到许多技巧和代码。

Still if you have problem. 仍然,如果您有问题。 Insert the content of the excel in to @table or permenant table and provide Collation to that table while selecting for comparison 将excel的内容插入到@table或permenant表中,并在选择进行比较时提供对该表的排序规则

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM