Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server query against two linked databases using different collations

I've got 2 remote databases as part of a query

select p.ID,p.ProjectCode_VC,p.Name_VC,v.*
FROM [serverB].Projects.dbo.Projects_T p
LEFT JOIN [serverA].SOCON.dbo.vw_PROJECT v on
p.ProjectCode_VC = v.PROJ_CODE

The problem is that serverA uses collation Latin1_General_BIN and serverB uses Latin1_General_CP1_CP_AS and the query refuses to run.

Both servers are SQL 2000 servers. Both databases are set in stone so I cannot change their collations, unfortunately.

Is there anyway you guys know how to get this to work?

Update: I found an alternative solution. In the Linked Server Properties, you can specify the linked server's collation there.

like image 205
Phil Bennett Avatar asked Jun 25 '26 17:06

Phil Bennett


2 Answers

Just add the collation to your select, like:

select 
  p.ID,
  p.ProjectCode_VC,
  p.Name_VC,
  v.* 
FROM
  [serverB].Projects.dbo.Projects_T p 
  LEFT JOIN [serverA].SOCON.dbo.vw_PROJECT v on p.ProjectCode_VC 
    collate Latin1_General_Bin = v.PROJ_CODE

or the other way around. So "convert" one of the collations to the other.

like image 99
Biri Avatar answered Jun 28 '26 12:06

Biri


Or you can use a more generic query like this:

select * from profile, userinfo
where profile.custid collate database_default = userinfo.custid collate database_default
like image 31
djoko soewarno Avatar answered Jun 28 '26 12:06

djoko soewarno



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!