Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

SQL Server Error 549: Collation Mismatch Fix

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

SQL Server error 549 means the variable or column you are assigning to has a different collation from the value you are assigning, and SQL Server will not implicitly convert between them in that direction. The fix is to make both sides use the same collation explicitly: either declare the receiving variable or column with the collation of the source, or apply a COLLATE clause to the source expression so it matches the receiver. The exact message usually reads "The collation of the receiving variable is not..." and it appears most often in stored procedures, table-valued functions and cross-database or cross-server queries where the two objects were created under different server or database collations.

What You'll Need

  • Permission to view object definitions in the affected database (at minimum, VIEW DEFINITION on the objects involved).
  • Permission to alter the procedure, function or table that is throwing the error.
  • A way to query sys.databases, sys.columns and sys.parameters to see the collations in play.
  • SQL Server Management Studio (SSMS) or Azure Data Studio, or any client that lets you run ad hoc T-SQL.

Step-by-Step

  1. Reproduce the error and note the object. Run the statement or procedure that fails and write down the exact object name in the message. Error 549 is raised at the point of assignment, so the object named is the procedure, function or trigger that contains the offending SET or SELECT ... INTO statement.
  2. Find the receiving variable or column. Open the object definition (in SSMS, right-click the object and choose Script as > CREATE To, or query sys.sql_modules). Look for DECLARE @var nvarchar(...) or a table column that is the target of an assignment. The receiver's collation is what matters.
  3. Check the collation of the receiver. For a variable, the collation is inherited from the current database unless you declared it with COLLATE. Run SELECT DATABASEPROPERTYEX(DB_NAME(), 'Collation') in the database where the procedure lives. For a column, run SELECT name, collation_name FROM sys.columns WHERE object_id = OBJECT_ID('dbo.YourTable').
  4. Check the collation of the source. If the source is a column in another database, query sys.columns there. If it is a literal or a variable, its collation comes from the database context at the time of the statement. Compare the two values; they will differ, for example SQL_Latin1_General_CP1_CI_AS versus Latin1_General_100_CI_AS_SC.
  5. Apply an explicit COLLATE clause to the source. The safest fix is to make the source match the receiver, not the other way around, because changing the receiver can break other callers. For example: SET @local = (SELECT Name COLLATE SQL_Latin1_General_CP1_CI_AS FROM OtherDb.dbo.Customers WHERE Id = @id); Use the exact collation name returned in step 3.
  6. Or declare the receiver with the source's collation. If the variable is local to the procedure and nothing else depends on its collation, declare it explicitly: DECLARE @name nvarchar(100) COLLATE Latin1_General_100_CI_AS_SC; This is often cleaner when the procedure only reads from one external database.
  7. For table columns, alter the column collation only as a last resort. Changing a column's collation affects indexes, joins and every query that touches it. Prefer applying COLLATE in the query. If you must alter it, script the change, test on a copy, and remember that indexed columns require dropping and recreating the index.
  8. Recompile and retest. After editing the procedure or function, run EXEC sp_recompile 'dbo.YourProcedure'; and execute it again. Confirm the error is gone and that results are correct, especially if the two collations differ in case sensitivity or accent sensitivity.

Common Mistakes

  • Putting COLLATE on the wrong side. The clause must be on the source expression so it matches the receiver. Adding it to the receiver does nothing useful in this error.
  • Guessing the collation name. Collation names are exact. Copy the value from sys.columns or DATABASEPROPERTYEX rather than typing from memory.
  • Changing the database collation to fix one query. Altering a database collation is a large, risky operation and will not fix cross-database assignments anyway.
  • Ignoring case or accent sensitivity. Two collations can look similar but differ in _CS versus _CI or _AS versus _AI. Matching only the language part is not enough.
  • Forgetting linked-server and cross-database contexts. The same procedure can work in one database and fail in another because the variable inherits the caller's database collation.

Tips

  • Use COLLATE DATABASE_DEFAULT when you want the source to match the current database without hard-coding a name. It is portable across environments.
  • Standardize collations across databases that exchange data. This prevents the error class entirely rather than patching each query.
  • Keep a note of the collation of each database in your environment; it saves time when a new cross-database procedure fails.
  • Test with data that exercises case and accent differences, not just a single row, to confirm the chosen collation behaves as expected.

Troubleshooting

If the error persists after adding COLLATE, check that you edited the correct object and that no nested procedure or function is raising the error. Use the object name in the message, not the outer procedure you called. If the message names a table variable or a table-valued parameter, the collation is fixed at declaration; you must change the declaration or the source. If you cannot alter the procedure, wrap the call in a new procedure that performs the assignment with explicit collation and returns the result. If the error appears only under certain logins, check whether the default database of those logins differs, because variable collation follows the current database context. Finally, if the two collations differ in Unicode versus non-Unicode types, convert the source with CAST or CONVERT to nvarchar before applying COLLATE.

Frequently Asked Questions

What causes SQL Server error 549?

It is raised when an assignment tries to put a value with one collation into a variable or column with a different collation, and SQL Server cannot implicitly convert between them.

Can I fix it without changing the procedure?

Only by changing the data source or the receiver. If you cannot edit either, create a wrapper procedure that performs the assignment with an explicit COLLATE clause.

Does COLLATE affect performance?

Applying COLLATE to a column in a predicate can prevent index seeks. Applying it to a variable or a projected expression usually has little effect. Prefer matching collations at the schema level where possible.

Why does the same code work in one database but not another?

Variables inherit the collation of the current database. If the procedure runs in a database with a different collation, the receiver changes and the mismatch appears.

Is error 549 the same as a collation conflict in a JOIN?

No. A JOIN conflict is error 468. Error 549 is specifically about assignment to a variable or column.

Can I use DATABASE_DEFAULT instead of a named collation?

Yes. COLLATE DATABASE_DEFAULT makes the source match the current database and is portable, but confirm the current database is the one whose collation the receiver uses.