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
andSQL_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?
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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With