My problem is occurring with a "simple-as-it-gets" IF statement, making the suggested fixes to many similar questions (e.g. Cannot resolve the collation conflict in my query) seemingly useless.
The error message is :
Msg 468, Level 16, State 9, Procedure #XYZ, Line 11
Cannot resolve the collation conflict between "Latin1_General_CI_AS" and "SQL_Latin1_General_CP1_CI_AS" in the equal to operation.
It's known that the server collation is set to SQL_Latin1_General_CP1_CI_AS
.
This query demonstrates the problem :
-- this procedure (which gets put into tempdb) is called WITHOUT specifying @Choice
CREATE PROCEDURE #XYZ
(
-- all other parameters removed (none of them have default values)
@Choice AS NVARCHAR(1) = 'Y'
)
AS
BEGIN
IF (@choice = 'Y') -- error raised here
BEGIN
DECLARE @NULL_STATEMENT AS int -- only here because there's no "do nothing" statement
END
RETURN
END
How can I fix this, given that altering the default collation of the server (and/or all of the tables) is NOT going to happen AND it is impractical to insert "COLLATE DATABASE_DEFAULT" in all queries, tables, etc. (for this solution see https://www.mssqltips.com/sqlservertip/4395/understanding-the-collate-databasedefault-clause-in-sql-server/ and Cannot resolve the collation conflict between temp table and sys.objects).
Closely related links:
Documentation of the COLLATE clause: https://learn.microsoft.com/en-us/sql/t-sql/statements/collations?view=sql-server-2017
A solution that I probably cannot use: https://www.mssqltips.com/sqlservertip/2901/how-to-change-server-level-collation-for-a-sql-server-instance/