Doing a join across two databases with different collations on SQL Server and getting an error

前端 未结 2 632
忘了有多久
忘了有多久 2021-01-30 08:32

I know, I know with what I wrote in the question I shouldn\'t be surprised. But my situation is slowly working on an inherited POS system and my predecessor apparently wasn\'t

相关标签:
2条回答
  • 2021-01-30 08:54

    A general purpose way is to coerce the collation to DATABASE_DEFAULT. This removes hardcoding the collation name which could change.

    It's also useful for temp table and table variables, and where you may not know the server collation (eg you are a vendor placing your system on the customer's server)

    select
        sone_field collate DATABASE_DEFAULT
    from
        table_1
        inner join
        table_2 on table_1.field collate DATABASE_DEFAULT = table_2.field
    where whatever
    
    0 讨论(0)
  • 2021-01-30 09:06

    You can use the collate clause in a query (I can't find my example right now, so my syntax is probably wrong - I hope it points you in the right direction)

    select sone_field collate SQL_Latin1_General_CP850_CI_AI
      from table_1
        inner join table_2
          on (table_1.field collate SQL_Latin1_General_CP850_CI_AI = table_2.field)
      where whatever
    
    0 讨论(0)
提交回复
热议问题