SQL Server - Cannot resolve collation conflict for equal to operation

[复制链接]
查看11 | 回复4 | 2007-4-13 01:05:37 | 显示全部楼层 |阅读模式
各位大虾:
我在SQL Server中运行Procedure的时间,报错:信息如下:
Cannot resolve collation conflict for equal to operation
请各位大虾指教!
回复

使用道具 举报

千问 | 2007-4-13 01:05:37 | 显示全部楼层
Answer:
This will occur when your query attempts to join a user
table to a temporary table, and the tempdb database collation differs from the user
database collation (sp_helpdb will show you default database collation).
To fix this, you can either:
1) Locate the query that is raising the error,
identify the join expression and use the COLLATE clause to tell SQL
which collation to use so that the query semantics aren't ambiguous.
OR
2) Change the collation of the temp db database to be consistent between the databases.
For example, we get the error when running the select in this query:
CREATE TABLE #ClientSummary
(
ClientID varchar(6) ,
CoName varchar(100),
AccountManager varchar(6),
CountOfInvoice int,
LongestDaysOS int,
[Name] varchar(255),
TotalInvoiceOSAmt money,
DatePromisedToPay datetime,
DateofLastReminder datetime,
DaysSinceLastReminder int,
ReminderTypeLastSent int,
AmountOfLastPayment money,
DaysSinceLastPayment int,
DateofLastPayment datetime,
RecommendedReminder int
)

SELECT
#ClientSummary.ClientID,
DateOfLastReminder = MAX(ClientDiary.DateCreated),
DaysSinceLastReminder = DATEDIFF(day,MAX(ClientDiary.DateCreated), getdate())
FROM
ClientDiary INNER JOIN #ClientSummary
ON ClientDiary.ClientID = #ClientSummary.ClientID
WHERE
ClientDiary.CategoryID LIKE 'DEBT-%'
GROUP BY
#ClientSummary.ClientID

Instead, use this for the select statement, with the COLLATE database_default
clause :
SELECT
#ClientSummary.ClientID,
DateOfLastReminder = MAX(ClientDiary.DateCreated),
DaysSinceLastReminder = DATEDIFF(day,MAX(ClientDiary.DateCreated), getdate())
FROM
ClientDiary INNER JOIN #ClientSummary
ON ClientDiary.ClientID = #ClientSummary.ClientID COLLATE database_default
WHERE
ClientDiary.CategoryID LIKE 'DEBT-%'
GROUP BY
#ClientSummary.ClientID
NOTE: You will have to recreate the tempdb database (or DTS the relevant user database into a blank database with the correct collection) if you want to do a join on a datetime field.
回复

使用道具 举报

千问 | 2007-4-13 01:05:37 | 显示全部楼层
按照这个方法,我把我临时表的Collation修改的和Db一样就好了,现在可以了!
回复

使用道具 举报

千问 | 2007-4-13 01:05:37 | 显示全部楼层
哪里的高手这么说的啊?不是CSDN吧?
回复

使用道具 举报

千问 | 2007-4-13 01:05:37 | 显示全部楼层
在www.baidu.com搜的!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行