[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now


Cross database query and collation

Posted on 2004-10-28
Medium Priority
Last Modified: 2008-03-03

I work for a software house and produce a SQL Server based product.  As part of the next releases upgrade, I need to release an 'upgrade database' that will be used during the upgrade process to assist with the upgrade of the 'customer database'.  Whilst I can choose the collation of the 'upgrade database' I have no way of knowing what collation the 'customer database' will use.

I need to run a query that does something like this

UPDATE <customer_database.table>
SET  <customer_database.table.field> = <upgrade_database.table.field1>
FROM <upgrade_database.table>, <customer_database.table.field>
WHERE <customer_database.table.field> = <upgrade_database.table.field2>
AND other criteria

When it executes, presumably becuase of the different collation settings, I get the error :-
Server: Msg 446, Level 16, State 9, Line 1
Cannot resolve collation conflict for equal to operation.

Note the upgrade database is a generic database that will be supplied by us as the software house.  Thus we no chance to change the upgrade database collation settings for each customer.  Obviously we cant change the customer database collation.

Hence I'm guessing there must be some clause I can add to the SQL to resolve the collation problem.

Please help...its urgent
Thanks in advance

Question by:meowsh
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 26

Expert Comment

ID: 12432689

UPDATE <customer_database.table>
SET  <customer_database.table.field> = <upgrade_database.table.field1>
FROM <upgrade_database.table>, <customer_database.table.field>
WHERE <customer_database.table.field> = <upgrade_database.table.field2> COLLATE <Your local collation>
AND other criteria

Author Comment

ID: 12432742

Thanks for the very quick reply.
How do I know what the local collation is?  Presumably the local collation is the collation of the customer database which is the bit I dont know.  The upgrade runs automatically on the customer database without any user interaction.  Do I need to query the system tables to work out the collation of the customer database.  How do I do that?  Or have I misinterpretted?

LVL 26

Accepted Solution

Hilaire earned 1200 total points
ID: 12432810
You can use the collation of your own DB
I think the collation you use doesn't really matter unless your customers are in countries that use special character sets, it's just that SQL Server can't choose for you which one to use when you compare two columns with different collations.

If you want to use the customerDB's collation, you'll need to use dynamic SQL :-(

You can get default DB collation like this
select databasepropertyex(db_name(), 'Collation')

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how the fundamental information of how to create a table.

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question