Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot resolve the collation conflict between temp table and sys.objects

The following T-SQL code:

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

Returns this error:

Msg 468, Level 16, State 9, Line 4

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

I tried appending this to the query, but it still returns the same error:

COLLATE SQL_Latin1_General_CP1_CI_AS ASC

How can I fix this?

like image 427
Danny Beckett Avatar asked Aug 19 '12 16:08

Danny Beckett


People also ask

How do you set a temp table collation?

If you create a temporary table, the columns in the temporary table get the default collation of tempdb (which is also the default collation of master and model). However, you can use DATABASE_DEFAULT to force the collation to match the default collation of the current database.

Is SQL_Latin1_General_CP1_CI_AS the same as Latin1_General_CI_AS?

The SQL_Latin1_General_CP1_CI_AS collation is a SQL collation and the rules around sorting data for unicode and non-unicode data are different. The Latin1_General_CI_AS collation is a Windows collation and the rules around sorting unicode and non-unicode data are the same.

What is collate SQL_Latin1_General_CP1_CI_AS in SQL Server?

The collate clause is used for case sensitive and case insensitive searches in the columns of the SQL server. There are two types of collate clause present: SQL_Latin1_General_CP1_CS_AS for case sensitive. SQL_Latin1_General_CP1_CI_AS for case insensitive.

What is collate Latin1_General_CS_AS in SQL Server?

According the SQL Server Books Online, the characters included in range searches depend on the sorting rules of the collation. Collation Latin1_General_CS_AS uses dictionary order so both upper and lower case characters of the specified range are included.


1 Answers

Add the following to any field that produces this error, in the WHERE or ON (JOIN) Clause: COLLATE DATABASE_DEFAULT.

e.g. (Your Question Above)

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
like image 122
Angoranator Avatar answered Oct 09 '22 09:10

Angoranator