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

前端 未结 2 631
忘了有多久
忘了有多久 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
    

提交回复
热议问题